DataObject references retained for life of application

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

DataObject references retained for life of application

aacain
Are DataObjects retained in memory for the life of the application?

I discovered the DataObject.find method returns the same instance each time
it is called.  How I discovered this:

* create a wizard that uses an explorer provider
* create a new abstract node as the root
* the children of the root are the dataobjects
* close the wizard
* reopen the wizard which creates a new abstract node and tries to create
the dataobject children

The first time the wizard is open, everything works as expected.  However,
when the wizard is opened for the second time, I receive an
IllegalStateException.  This is because the dataobject children nodes are
trying to be assigned to a new parent node. The api does not allow the nodes
to have a reassigned parent node and I get the illegalStateException.  This
can only happen if the getNodeDelegate returns the same node in both runs of
the wizard.  The reference to the dataobject is lost when the wizard
executes, so there must be some other reference to the dataobject because
the DataObject.find method returns the same instance of the dataobject.
This means that the getNodeDelegate method also returns the same instance of
the node from the first run.

For my application, I do not want keep these data objects in memory for the
life of the application.  Is there any way around this?

As a side note, I resolved the IllegalStateException by implementing the
code as follows:

//Works
public OboSelectVisualPanel() {
        this.em = new ExplorerManager();
        try {
            DataObject rdo =
DataObject.find(FileUtil.getConfigFile("OboFiles"));
            em.setRootContext(rdo.getNodeDelegate());
        } catch (DataObjectNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
}

//Doesn't work the second+ time the panel is created
public OboSelectVisualPanel() {
        this.em = new ExplorerManager();
        try {
            DataObject rdo =
DataObject.find(FileUtil.getConfigFile("OboFiles"));
            AbstractNode root = new AbstractNode(new
CreateDataChildren(rdo));
            em.setRootContext(root);
        } catch (DataObjectNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
}

-AC



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: DataObject references retained for life of application

Jesse Glick-2
On 02/22/2012 01:48 PM, Aurora Cain wrote:
> Are DataObjects retained in memory for the life of the application?

No, they are cached but should be garbage-collected at some point if the FileObject is.

> I receive an
> IllegalStateException.  This is because the dataobject children nodes are
> trying to be assigned to a new parent node. The api does not allow the nodes
> to have a reassigned parent node and I get the illegalStateException.

Right, DataObject.createNodeDelegate() may only be used once. Use cloneNode() if you want to add a node delegate to your own Children instance.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: DataObject references retained for life of application

aacain
If I am interpreting the javadoc correctly, it seems the node created from the cloneNode method should not be assigned as a child to any other node:

public abstract Node cloneNode()
Clone the node. The newly created node should reference the same object is this node does, but it should not be inserted as a child to any other node. Also it should have an empty set of listeners. In all other respects the node should behave exactly as the original one does.
Returns:
copy of this node

I have the Explorer view working fine.  The point of this email was really just to make sure that when a dataobject is created that it only has a weak or soft reference.  If not, I would create a different wrapper for my fileobject that didn't persist the entire application.

Seems like the DataObject is a good choice.

AC

-----Original Message-----
From: Jesse Glick [mailto:[hidden email]]
Sent: Wednesday, February 22, 2012 3:03 PM
To: [hidden email]
Subject: [nbdev] Re: DataObject references retained for life of application

On 02/22/2012 01:48 PM, Aurora Cain wrote:
> Are DataObjects retained in memory for the life of the application?

No, they are cached but should be garbage-collected at some point if the FileObject is.

> I receive an
> IllegalStateException.  This is because the dataobject children nodes
> are trying to be assigned to a new parent node. The api does not allow
> the nodes to have a reassigned parent node and I get the illegalStateException.

Right, DataObject.createNodeDelegate() may only be used once. Use cloneNode() if you want to add a node delegate to your own Children instance.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: DataObject references retained for life of application

Jesse Glick-2
On 02/22/2012 04:52 PM, Aurora Cain wrote:
> If I am interpreting the javadoc correctly, it seems the node created from the cloneNode method should not be assigned as a child to any other node:

Seems the Javadoc is exactly backwards; I will improve it. Thanks for catch.

Loading...