Destroy consume memory
hello friends
i have develop one application in which i have lots of images and sound,
i can release sound easily by release()
method but i can't able to release image.
s开发者_开发技巧ystem.gc()
function but it is not working for image i thing it is garbage collector.
second thing is that can you give me precaution step against memory management
(regarding of image,sound & codeing part also)
Thanks nik
Invocations of System.gc()
are only suggestions to run the garbage collector. The GC need not run immediately.
I believe such complex applications would benefit from using an MVC model. The Model (or logic) class can save the required images and sounds to a cache folder, and just pass the list of file paths to the view (Activity) which can read and display on-demand, de-referencing any assets that are no longer required.
Also, it would help to reduce the asset sizes (images and sounds) by lowering resolutions (image) or downsampling (audio), wherever possible.
Update: - For downsampling images, check this link: http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize
MVC is slightly tougher to implement in Android due to the fact that Activities are the entry points. So, what can be done is that a singleton "Model" object can be created, which can be accessed from anywhere. Similarly, a singleton "Controller" object can also be created. The activity can notify the controller when it requires an asset, and the controller will forward the request to the model.
精彩评论