Managed object life cycle

All creates, reads, updates, and deletes of Managed Objects must be done in a transaction. Creating an object in a transaction that rolls back removes the object from shared memory. Deleting an object in a transaction that rolls back leaves the object in shared memory.

Managed Objects are not garbage collected by the JVM. Although the proxy Java object that references the Managed Object may be garbage collected, the shared memory state of the object remains. Managed Objects must be explicitly deleted by calling the delete method.

Example 5.7. Deleting managed objects

//     $Revision: 1.1.2.1 $

package com.kabira.snippets.managedobjects;

import com.kabira.platform.Transaction;
import com.kabira.platform.ManagedObject;
import com.kabira.platform.annotation.Managed;

/**
 *  Deleting a managed object
 * <p>
 * <h2> Target Nodes</h2>
 * <ul>
 * <li> <b>domainnode</b> = A
 * </ul>
 */
public class Delete
{
    /**
     * A managed object
     */
    @Managed
    public static class MyObject { };
    
    /**
     * Main entry point
     * @param args  Not used
     */
    public static void main(String [] args)
    {
        new Transaction("Delete Object")
        {
            @Override
            protected void run() throws Rollback
            {
                MyObject    e = new MyObject();

                //
                //    Delete instance in shared memory
                //
                ManagedObject.delete(e);
           }
        }.execute();
    }
}

After the ManagedObject.delete method is called on a Managed Object, using the Java reference to invoke methods or access a field will cause this exception to be thrown.

java.lang.NullPointerException

The ManagedObject.isEmpty() method can be used to test whether the shared memory backing a Java reference has been deleted.

If a managed object contains any by-reference fields, the non-managed object stored in the by-reference field is not eligible for garbage collection until the field is cleared, or the containing managed object is deleted.