Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to handle Memory Leak (Read 4200 times)
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
How to handle Memory Leak
Apr 23rd, 2021 at 6:52am
Print Post  
Hi,

We observed objects and nodes associated with diagram and diagram elements are not released. we tried with diagram.clearAll() and diagram.dispose() but still same memory leak observed. So can you suggest steps to avoid memory leak related to diagrams?

Regards,
Kannan
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: How to handle Memory Leak
Reply #1 - Apr 23rd, 2021 at 8:48am
Print Post  
Hi,

Chrome profiler shows nodes getting deleted for us after clearAll. If you are seeing any items remaining in memory, you can inspect the Retainers panel to find out what keeps them referenced.

Regards,
Slavcho
Mindfusion
  

mem1.png (Attachment deleted)
mem2.png (Attachment deleted)
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: How to handle Memory Leak
Reply #2 - May 4th, 2021 at 7:46am
Print Post  
Hi,

We have tried clearing elements using clearAll and followed by dispose methods, but we are seeing nodes are retaining in memory. The object which creating diagram element and adding items has been removed from the memory. When exploring in chrome dev tool, we observed FBDiagramLink retained with the reference “incomingLinks in aDf.DummyNode”. We have customized and extended nodes and we have nodes such as FBDiagramShapeNode extended Mindfusion.Diagraming.ShapeNode and FBDiagramLink extended Mindfusion.Diagraming.DiagramLink and FBDiagramTableNode extended Mindfusion.Diagraming.TableNode and like that.

We also observed adt.diagram objects retained in object but there is no reference from other objects and observable from code.

Could you please suggest some solution or what could be reason from diagram?

Regards,
Kannan
  

DiagramClearAll.png (Attachment deleted)
DiagramClearAll-2.png (Attachment deleted)
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: How to handle Memory Leak
Reply #3 - May 4th, 2021 at 8:55am
Print Post  
Hi,

If you create 'unconnected' links, i.e. connecting to a point of the diagram instead of a node, they get actually connected to the diagram.dummy node instance. Try setting its incomingLinks and outgoingLinks fileds to empty arrays for cleanup; clearAll doesn't do that at this time.

Quote:
We also observed adt.diagram objects retained in object but there is no reference from other objects and observable from code.


Objects without path to them from root window should get garbage-collected at some point, so these shouldn't be a problem unless you are seeing Chrome show the reachable-from-window icon for them.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: How to handle Memory Leak
Reply #4 - May 4th, 2021 at 9:09am
Print Post  
And instead of keeping the diagram instance and clearing its items, you could also try disposing of old diagram and creating a new one.
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: How to handle Memory Leak
Reply #5 - May 5th, 2021 at 5:02am
Print Post  
Hi,

We tried to set node’s incomingLinks and outgoingLinks to empty array but it didn’t help and tried setting diagram.dummy = null or diagram.dummy.incomingLinks = [] then it worked and all nodes collected by GC


Old code (retained node objects in memory)

               diagram.clearAll();

               diagram.dispose();

               diagram = null;



New Code (removed node objects from memory)

                 diagram.dummy = null;

                 diagram.clearAll();

                 diagram.dispose();

                 diagram = null;

   

I observed the diagram object adt.diagram is retained even after a long time also it is not collected by GC. It has some indirect reference from windows through zone. This is the most reason for retention of diagram object and dummy object which has the collection of incoming links.



When explored actual reference, I found following event listener and delegates from diagram class

  'registerDisposableObject': function registerDisposableObject(bP) {

      window['addEventListener'](b('0x2c'), function () {

        bP[b('0x2d')]();

      });

    }

Could to tell me what could be the reasons for it from diagram and please suggest me some solution?

Regards,
Kannan
  

DiagramDispose-1.png (Attachment deleted)
DiagramDispose-2.png (Attachment deleted)
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: How to handle Memory Leak
Reply #6 - May 5th, 2021 at 7:27am
Print Post  
Hi,

This method registers "unload" event handler. You could replace it with a noop before creating diagrams -

MindFusion.AbstractionLayer.registerDisposableObject = function(){};

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Kannan Thirumal
Senior Member
****
Offline


I Love Mind Fusion Diagram
:-)

Posts: 284
Location: Bangalore, India
Joined: Jan 18th, 2019
Re: How to handle Memory Leak
Reply #7 - May 5th, 2021 at 11:40am
Print Post  
Hi,

As your suggestion setting function registerDisposableObject as below, resolved window reference from through this function.

MindFusion.AbstractionLayer.registerDisposableObject = function(){};



Still one reference from window through function “createDelegate” keep diagram object alive. Please refer above screenshot. If we could resolve this one, mostly the diagram object will be free for GC collection. Could you please suggest some solution for it?

Regards,
Kannan
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: How to handle Memory Leak
Reply #8 - May 5th, 2021 at 12:48pm
Print Post  
Hi,

Try window.removeEventListener("resize", diagram.resizeDelegate);

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint