Home > Uncategorized > Netbeans DataObject life cycle

Netbeans DataObject life cycle

Here are some questions which I did not found any answer on the Netbeans wiki:

  • When are DataObject created
  • When are DataObject destroyed
  • Am I expected to store custom data in DataObject

Answers can be found in the openide.loaders/src/org/openide/loaders/DataObjectPool.java file, in the source code:

  • DataObject are, at least, created when Netbeans need to display a Node representing a FileObject, that is, each time an explorer browse a file system.
  • DataObject are stored as WeakReference in the DataObjectPool instance. They are freed when memory is required.
  • As you do not control when DataObject are created nor disposed you should probably not load nor store data when the DataObject is created. It should be done by actions associated to the DataObject.

There is a funny side efect of using WeakReference to keep track on DataObject. If you open a directory with a lot’s of large DataObject, some of them may be destroyed by the garbage collector as soon are the are created. Then corresponding nodes are not displayed.

Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: