Parsley dependency injection memory leak

In short:
When using Parsley's Context for dependency injection, You should call destroyObject() on each getObject() call, otherwise you may have a memory leak.
Long story:
Lately I was dealing with some memory leaks issues in one of our client's systems which use Parsley for dependency injection via its Context .
Turns out that calling Context.getObject(id) internally creates references to the objects used for creating the injected object.
These references are not released, and may cause a memory leak.
The profiler (FB4) looks something like this (namespaces ommited for client's privacy sake):



 As you can see, DefaultContext has a lifecycleManager property of type DefaultObjectLifecycleManager, which owns a dependentInstances dictionary which is used for storing the objects which the instantiated object depends on (such as objects used for its constructor or properties).
These are added when you call context.getObject().
In order for these references to be released, you should explicitly call destroyObject on this manager after you are done with it.
A typical code for doing so may look like this :


myDIObject = context.getObject(DIobject_id);
if (myDIObject) {
// Do something with the created object

//destroying the object's references in Parsley
var definition:ObjectDefinition = DefaultContext(context).registry.getDefinition(DIobject_id);




and the memory leak is gone :)

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at