Created
March 12, 2012 00:05
-
-
Save newbyca/2018775 to your computer and use it in GitHub Desktop.
workaround class for Android Typeface.createFromAsset memory leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks so much!