views:

103

answers:

4

Hi all,

Im currently developing a software under android and im getting quite quickly some OutOfMemoryException.... I did modified some part of my code to use more static variables instead of making new allocation with the "new" operator but is there any things else to do ? or any other tips ? Any advices would be welcome.

Thanks.

+2  A: 

You can find a lot of tips here: http://developer.android.com/guide/practices/design/performance.html

Especially look at the Avoid Creating Objects topic.

benvd
+1  A: 

You can also watch some Google I/O conferences, like the ones about writing non-janky apps or how to make fast and efficient apps from 2009.

Rorist
+1  A: 

If you have some resources that can be reloaded onto memory anytime, consider using WeakReferences. The objects inside them will be cleared just before the (Java) VM throws OutOfMemoryException, so there will be some more memory available.

yuku
What is it a WeakReference ?
Fabien
http://developer.android.com/reference/java/lang/ref/WeakReference.html
yuku
+1  A: 

You may be accessing too many resources (such as images) before garbage collector can handle/recycle them. If you're accessing particularly large images, then use BitmapFactory to scale them down, as seen answered on SO. (Of course, for this you would see something like "bitmap size exceeds vm budget" in your logcat too.) Any more details on the error?

gary comtois
Well, im loading a bunch of small images in a function. But if I call several time this function, it will run out of memory. Its doesnt look so much to clean everything in between the difference time call. I have worked on my code to use more static variables but i saw in some case you cannot use them, especially when dealing with adapter or view objects...
Fabien
You can try manual garbage collection when you don't need that particular bitmap. Code is bitmap.recycle(). I have not tried it but have seen it referenced here many times.
gary comtois