Welcome!

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

Reply
Developer
barees63
Posts: 122
Registered: ‎07-26-2008
My Device: 8320, 9500, 9700

Releasing Persistent Objects?

I have a basic memory management question:

 

Say I have a BigVector holding 500 persistent objects which consumes around 2MB.

 

Each object is grouped.

 

I would like to be able to free this vector and release all the memory used, I have tried various things including removing each object from the vector, calling LowMemoryManager.markAsRecoverable on each, committing the empty vector and calling System.gc()

 

No matter what I try I don't seem to recover the memory until I reset the device (at least according to Options --> Status --> File Free).

 

What is the correct way to destroy persistent objects and recover the memory immediately?

 

Thanks!

Bruce

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Releasing Persistent Objects?

Probably a silly question, but have you tried calling the garbage collector (System.gc())?
Developer
smiley
Posts: 1,497
Registered: ‎07-14-2008
My Device: Z10

Re: Releasing Persistent Objects?

I'm my app i just call PersistentStore.destroyPersistentObject().

I would assumed this will free the allocated memory. 

Developer
barees63
Posts: 122
Registered: ‎07-26-2008
My Device: 8320, 9500, 9700

Re: Releasing Persistent Objects?


smiley wrote:

I'm my app i just call PersistentStore.destroyPersistentObject().

I would assumed this will free the allocated memory. 


In my case I don't want to remove the entire hashtable that I have in PersistentStore, just elements from one vector which is contained in it.  So my question could be rephrased as "how do I release individual grouped persistent objects without destroying the entire store and ensure that the memory is recovered immediately?"

 

 

Developer
barees63
Posts: 122
Registered: ‎07-26-2008
My Device: 8320, 9500, 9700

Re: Releasing Persistent Objects?

Well, it looks like the "File Free" status value is just confusing me, if I "release" 500 objects the value does not change (unless I reset the device), but if I then create another 500 objects the value still doesn't change so I assume the subsequent allocation is using the previously freed memory?

 

Should I be this confused or am I missing something obvious? :smileyindifferent:

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Releasing Persistent Objects?

Resetting the BlackBerry results in a full garbage collection, which would reclaim the memory you are using.  There is no way to guarantee that your memory is immediately freed.  I recommend you have a look at the "Garbage collection in the BlackBerry Java Development Environment" and "Low memory management in the BlackBerry Java Development Environment" white papers found here: 

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe?func=ll&objId=832210&objAction=browse&s...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker