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
New Developer
Posts: 58
Registered: ‎08-05-2009
My Device: Not Specified

BlackBerry persistent storage

Hi, my friends, i have a qustion about BlackBerry persistent storage. I wil use BlackBerry persistence model to store my individual data on BB. I have read the introduce about that. In the example they showed how man store only one object and later retrieve that.

Can anybody tell me, when i have stored more than one object in a PersistentObject, what would i get when i invoke the function "getContents( )"? Shall i get the last stored object or the all stored objects?

After i retreive a object from the PersistentObject, will the memoryspace of the retreived object automated be released? Works a PersistentObject with the mechansim FIFO or LIFO?

 

Thank you in advanced!

Highlighted
Developer
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700
My Carrier: Vodafone UK

Re: BlackBerry persistent storage

You'll get one object back BUT if you have stored multiple objects within it you will get them all back, Such as a Vector or Hashtable may have multiple objects in them.

 

 Retrieving a Persistent Object itself will return one object.

If for some reason you want to be able to retrieve two separate objects from different locations in the store you could use two different keys and two different persistent objects.. Depends on how you want the data to be read/stored 

Genius Development Scotland
Website: http://www.genius-dev.co.uk
New Developer
Posts: 58
Registered: ‎08-05-2009
My Device: Not Specified

Re: BlackBerry persistent storage

Thanks geeneeus!

 

But can you answer my last question? Can the memory space of the retreived object automated be released?

Or can somebody else help me?

 

Thank you very much!

Developer
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700
My Carrier: Vodafone UK

Re: BlackBerry persistent storage

I'm not one hundred percent sure what you mean by can it be automatically released? 

Genius Development Scotland
Website: http://www.genius-dev.co.uk
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: BlackBerry persistent storage

you mean  release the memory allocated for that persistent object? if yes, try this one PersistentStore.destroyPersistentObject(). but not sure if it will release it right away because JVM's mechanism on garbage collection.

 

check this out for more information:

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/Garbage_collection_in_the_BlackBerry_Ja...

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/Low_memory_management_in_the_BlackBerry... 

Developer
Posts: 183
Registered: ‎12-17-2008
My Device: 8320

Re: BlackBerry persistent storage

Hi,

 

Your object's value is stored in flash memory via a deep copy.

 

memoryspace of the retreived object is not be released.

 

If you want to release you can use following method.

 

destroyPersistentObject(long key). It will Completely

 

delete your persistent object from flash memory.

kums

******************************

Press kudos which the post help you
Please mark posts as solved if you got a solution
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: BlackBerry persistent storage

Just to complete the story, here is a simplified version of what goes on

 

1) Object is created in RAM

2) Object is stored in PersistentStore, so now in Flash

3) Object is retrieved from PersistentStore, now have 2 copies, on in RAM, one in Flash.  The one in RAM will be lost if the device reboots.  The one in RAM is retained

4) Object is committed, so copy in RAM is now moved the Flash

 

As others have noted, to remove Object from Flash, you use destroyPersistentObject(id).  However note that if the Object is a class that is specific to your application, it will be also be removed from Flash if your application is deleted from the device.

 

I say simplified because in fact, as I understand it, the boundary between Flash and RAM is not as clear cut as that, and in fact Flash can be used to store 'temporary' Objects, which can then be committed.  In addition, the space used by now deleted Flash objects is not immediately cleaned up.  You can see more about this in the following video.

 

http://www.blackberry.com/DevMediaLibrary/view.do?name=GarbageCollection

New Developer
Posts: 58
Registered: ‎08-05-2009
My Device: Not Specified

Re: BlackBerry persistent storage

" I'm not one hundred percent sure what you mean by can it be automatically released? "

I mean that the space can be used for another application or for this application but for another data storage.

 

Thanks johnbibs, kumaresan and peter_strange. I will see the artical again.