Skip to content

Instantly share code, notes, and snippets.

@newbyca
Created March 12, 2012 00:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newbyca/2018775 to your computer and use it in GitHub Desktop.
Save newbyca/2018775 to your computer and use it in GitHub Desktop.
workaround class for Android Typeface.createFromAsset memory leak
public class Typefaces{
private static final Hashtable cache = new Hashtable();
public static Typeface get(Context c, String name){
synchronized(cache){
if(!cache.containsKey(name)){
Typeface t = Typeface.createFromAsset(
c.getAssets(),
String.format("fonts/%s.ttf", name)
);
cache.put(name, t);
}
return cache.get(name);
}
}
}
@slovenec88
Copy link

Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment