skip to main content
Programmer's documentation > Using graph layout algorithms > Using advanced features > Releasing resources used during the layout of a graph
 
Releasing resources used during the layout of a graph
Various objects need to be created during the layout process. Most commonly, these are:
*Layout instances (subclasses of IlvGraphLayout)
*Grapher adapters (subclasses of IlvGrapherAdapter)
*Other adapters (subclasses of IlvGraphModel)
*Layout providers.
For recursive layout, you may also instantiate layout providers (subclasses of IlvDefaultLayoutProvider). See also Recursive layout.
*Property objects
Some of the layout parameters are internally stored as property objects attached to the grapher object or to its nodes and links.
If you use a diagram component (a subclass of IlvDiagrammer) with styling, all created objects are automatically released when they are no longer used so that obsolete objects can be garbage-collected and memory leaks (in the Java™ sense) are avoided.
Rules for releasing resources
If you program graph layout directly in Java™, you must follow some rules to ensure that all these allocated objects are correctly released:
1. When a layout instance instantiated by your code is no longer useful, call the method detach() on it to ensure that no grapher or graph model is still attached to it. Note that you can freely reuse a layout instance once the previously attached model has been detached.
2. Layout parameters that are specific to a node or a link are cleaned when calling IlvGraphLayout.detach(). This cleaning is done only for nodes and links that are still in the grapher when the detach() method is called. If per-node or per-link parameters have been specified and the node or the link needs to be removed before the detach() method can be called, you can call the methods cleanNode or cleanLink of the class IlvGraphLayout to perform the cleaning for the node or the link. However, you only need to do so if the removed node or link is reused by your code after removal. Otherwise, if your code does not keep any reference to it, the node or link will be garbage collected anyway, together with the property objects eventually stored by the layout.
3. When a grapher adapter (or other graph models) instantiated by your code is no longer useful, call the method dispose() on it to ensure that the resources it has used are released. Note that an adapter (or graph model) must not be used once it has been disposed.
4. When a layout provider (an instance of IlvDefaultLayoutProvider ) instantiated by your code is no longer useful, call the method detachLayouts(model, true) on it, passing as arguments the graph models that have been used for performing a recursive layout with this provider.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.