Releasing non-persistant objects in a custom widget

2
I have a custom widget that calls a DataSource Microflow, which in turn can create a large amount of non persistant objects (somewhere in the 800-1000 range). The domain model is somewhat similar to the ChartJS widget: https://github.com/mendix/ChartJS. I noticed that thousands of the non-persistant entities would remain in the cache, slowing the application down. I believe this is solved in the ChartJS widget by the handle connecting to the context object and then releasing that handle in the "uninitialize". Is this assumption correct? I now tried to solve this by making an array of all items the DataSource created, and then doing this: uninitialize: function() { logger.debug(this.id + ".uninitialize"); // Clean up listeners, helper objects, etc. There is no need to remove listeners added with this.connect / this.subscribe / this.own. mx.data.release(this._ObjsArray); }, However I don't see them being deleted (I added a before_delete action with logging in Mx). Is this because the method I use is wrong? Or is this just because they are now ready for garbage collection but just not deleted yet? Also would it be better to work with "handle" or calling "mx.data.remove" in my initialize instead of the solution I chose now?
asked
1 answers
3

I don't think the platform triggers the delete event. Technically the object isn't deleted, it is no longer kept in memory. They have the same end result, but as far as I know we don't have an event that runs on cleanup in memory.

The most reliable way is to look at the cleanup debug messages from the platfrom.


You can enable TRACE logging for the LogNode: Core. The Core log node prints how many object it garbage collects, if objects are being garbage collected that lognode will print how many objects of each type are being removed.


Keep in mind though that objects are only removed from memory if the are no longer accessible through other objects in memory. During garbage collection the platform looks in memory. If the object is still associated to an object in use it will not be garbage collected. For example if your objects are associated to the currentUser, which is always kept in memory since he is logged in and the user info is stored in the session. If you would associate your non-persistent objects with the current user, they will never be garbage collected (until the session is destroyed).
But this same applies to something as simple as when you still have a dataview open in the browser, all associated non-persistent entities will stay in memory as long as that dataview object is used in the browser. When the client releases the dataview object, that object, and all associated objects will be garbage collected.

answered