Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Super Contributor
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

How to clear the ram memory.

Hi There,


in my application when i open around 15-20 screens it throughts out of memory error. i saw the memory stats ram was occupying the to much memory how can i freze that memory is there any methods available in bb to clear the Ram memory. any one help me on this to solve the issue.


i am poping all screens but that one wasn't helping me here.


i tried to popall screens and push a new screen also not clearing the memory. it clears the screen data a little bit.


Thanks in advance. 

Trusted Contributor
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: How to clear the ram memory.

Hai, You need to do few things to clear memory.

1.Pop up the current screens correctly after every push. Don't clos all screens on certain point.
2.Reuse the objects instead of creating new ones.
3.Don't use many String variables, Try to reduce and reuse the strings as it take more memory.
4.Try to reduce recursive functions repeatedly.
5.Use synchronized (UiApplication.getEventLock()) for Database connection it will reduce the time by lock the UI.
6.Try to reduce the Size of images with the help of graphic designer.


These are the simple steps to be concerned on development.

Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to clear the ram memory.

gopi has given you some good tips and ideas. 


I just wanted to add that the profiler is a good way to find out what Objects you are hanging on to. 


Remember that the garbage collector will tidy up the Objects that you are no longer using, but if it finds you still have a reference to it anywhere, it will not remove the Object.


In my experience, images tend to use more memory than anything else.