09-20-2009 04:25 PM
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!
09-20-2009 04:46 PM
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
09-20-2009 05:48 PM
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!
09-20-2009 09:58 PM
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:
09-21-2009 02:35 AM
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.
09-21-2009 04:40 AM
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.
09-21-2009 04:53 AM
" 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.