Jump to content
McObject Forums
Mikkel

My delete does not work

Recommended Posts

Mikkel    0

Hello,

I write some code to delete the data I added before. But it looks like it doesn't work. If I delete all data, and then make a reset and close the app I can see in the settings of my phone that the app still uses 4,5gb of diskspace for data.

I will attach a .txt file with my code used for delete and reset

Regards

Mikkel


 

Perst delete code example.txt

Share this post


Link to post
Share on other sites
perstmco    0

Perst never shrinks the size of a database. It just marks deallocated objects as free. This space will be reused by new allocation requests.
This space is not returned to the file system, so you will not see extra free space after the end of a bulk delete. You can use the compactify method to shrink the database.

Share this post


Link to post
Share on other sites
perstmco    0

It is Storage.backup method:

    /**
     * Backup current state of database
     * @param out output stream to which backup is done
     */
    public void backup(java.io.OutputStream out) throws java.io.IOException;
    /**
     * Backup current state of database to the file with specified path
     * @param filePath path to the backup file
     * @param cipherKey cipher key for the encryption oof the backup file, null to disable encryption
     */
    public void backup(String filePath, String cipherKey) throws java.io.IOException;

It performs backup of the storage file and defragment it at the same time.



 

Share this post


Link to post
Share on other sites
Mikkel    0

Inside this code I delete the data and made a backup. You said after delete all data and making a backup the internal storage gets free. But this is not working. After delete and backup the size needed from internal storage is the same size like before delete.

Share this post


Link to post
Share on other sites
perstmco    0

Excluding objects from index doesn't cause deallocation of object instances themselves.
You must explicitly call Deallocate() method for each object or use ITable.DeallocateMembers method.


 

Share this post


Link to post
Share on other sites
Mikkel    0

Hello,

I changed my code and add deallocate for each object. But after that the used storage size is the same like before. I will attach my new Code to this post.

Can you write me some example code how to completly delete single objects(with deallocation and so on)?

 

Perst delete Fahrt.txt

Share this post


Link to post
Share on other sites
perstmco    0

1. You should exclude objects from index(es) prior to deallocation it. I do not think that it will really cause a problem in your case, but in any case it is reasonable to exclude objects from indexes before deallocating them.

2. Deallocation of objects is done in many Perst examples. You can look at TestAlloc.java, for example.

3. It is not clear from your code what is the original size of the database and how many objects are actually deleted by deleteFahrt. If it deletes just a few objects that have a total size of less than one page, then the size of database after compactification could be the same as the original database.

Share this post


Link to post
Share on other sites
Mikkel    0
On 28.12.2016 at 7:45 PM, perstmco said:

1. You should exclude objects from index(es) prior to deallocation it. I do not think that it will really cause a problem in your case, but in any case it is reasonable to exclude objects from indexes before deallocating them.

I changed my code and now I remove the objects from index before I try to deallocate them. You can see my used code in the attached file.

2. Deallocation of objects is done in many Perst examples. You can look at TestAlloc.java, for example.
I looked into TestAlloc.Java, but I can't find some example.

3. It is not clear from your code what is the original size of the database and how many objects are actually deleted by deleteFahrt. If it deletes just a few objects that have a total size of less than one page, then the size of database after compactification could be the same as the original database.

I defined different scenarios. I run a small test with 1.000.000 objects and print out some stats from the databasesize. You can see the code of my test too in the attached file.
 DatabaseSize before insert:                               94208
 DatabaseSize after insert before delete: 220102656
 DatabaseSize after delete before reset:  219947008
 DatabaseSize after reset:                                    94208

 

 

 

PerstCode.txt

Edited by Mikkel
forget the code file

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×