friends,
any one guide me if there is any event of useful way exits in android to kno开发者_如何学Pythonw if my android application is running in low memory?
actually , i am caching many objects so i want to know a central place or area where i could release them if memory is low.
any help would be appreciated.
Contrary to what @bigstones says, onLowMemory()
doesn't exactly do what you would expect. My understanding of this call is that it is only reached when the system is low on memory and asks your application to free extra memory. onLowMemory()
will never be called when the system has plenty of memory, but your app has reached its memory limit.
It's also a bad idea to try/catch the OutOfMemory exceptions. If you want to know your own app's memory usage, the best way to get it is via the ActivityManager class, namely in the getMemoryClass()
and getProcessMemoryInfo()
methods.
Also, you should read this SO answer (from an Android engineer), which explains process memory use in a much more detailed way.
yes, see onLowMemory(), Activity and others implement this.
edit: this is actually wrong, application-wise. See Nik Reiman's answer.
OnLowMemory() only gets called when the system is running out of memory so with that you can implement following methods to check available memory before you decode the images.
Runtime.getRuntime().maxMemory();
Runtime.getRuntime().totalMemory();
Runtime.getRuntime().freeMemory();
精彩评论