• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 package com.badlogic.gdx.tests.extensions;
18 
19 import com.badlogic.gdx.Gdx;
20 import com.badlogic.gdx.files.FileHandle;
21 import com.badlogic.gdx.graphics.g2d.BitmapFont;
22 import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
23 import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData;
24 import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
25 import com.badlogic.gdx.tests.utils.GdxTest;
26 
27 public class FreeTypeDisposeTest extends GdxTest {
28 	BitmapFont font;
29 
30 	@Override
create()31 	public void create () {
32 		super.create();
33 	}
34 
render()35 	public void render () {
36 		if (Gdx.input.justTouched()) {
37 			for (int i = 0; i < 10; i++) {
38 				if (font != null) {
39 					font.dispose();
40 				}
41 				FileHandle fontFile = Gdx.files.internal("data/arial.ttf");
42 				FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
43 
44 				FreeTypeFontParameter parameter = new FreeTypeFontParameter();
45 				parameter.size = 15;
46 
47 				font = generator.generateFont(parameter);
48 				generator.dispose();
49 			}
50 			for (int i = 0; i < 10; i++)
51 				System.gc();
52 			Gdx.app.log("FreeTypeDisposeTest", "generated 10 fonts");
53 			Gdx.app.log("FreeTypeDisposeTest", Gdx.app.getJavaHeap() + ", " + Gdx.app.getNativeHeap());
54 		}
55 	}
56 }
57