Solved

Recursive calls to a method which creates a graph instance

  • 30 November 2022
  • 4 replies
  • 178 views

Userlevel 6
Badge +3

I’m a VB.Net guy, so this is probably more of a C# question.

On my processing page, I am calling a static void method.  In that method a graph instance is created.  This method might be called 100 times.

public static void DoIt(List<ICSCustomers> custList, RecordsToProcessFilter currentFilter) 

    var graph = PXGraph.CreateInstance<CustomersProcess>();

    //CODE 
}

After the DoIt method is completed, does the graph instance get destroyed, or does it stay in memory?  I am concerned that if I have 100 instances of that graph in memory it will cause problems.

If it does stay in memory, is there a way to destroy it at the end of the method?  I see I can “clear” it, but that isn’t the same as destroying it.

Thanks!

Joe

 

 

 

icon

Best answer by Leonardo Justiniano 30 November 2022, 18:45

View original

4 replies

Userlevel 6
Badge +4

Hi @joe21 

Call graph.Clear() at the end of your code.

Also note that C# GC (Garbage Collector) will take care of destroyed objects.

Depending on your caller, you could pass the graph as parameter. But you cannot avoid calling graph.Clear() at the end of your code.

 

Userlevel 7
Badge +5

@Leonardo Justiniano - just to confirm what you said about not being able to avoid calling graph.Clear() - does that mean that if I should explicitly call graph.Clear() every time that I have explicitly created a graph via graph.CreateInstance<>()? 

Userlevel 6
Badge +3

@Leonardo Justiniano- just to confirm what you said about not being able to avoid calling graph.Clear() - does that mean that if I should explicitly call graph.Clear() every time that I have explicitly created a graph via graph.CreateInstance<>()? 

I had the same question, but I just put it in at the end of the try-catch as I don’t think it can hurt anything since I don’t want to re-use it anyway.  I tested it on a few records and it worked fine for me doing that.

Userlevel 6
Badge +4

Hi @ddunn 

I always make sure the graph is cleared when I am done with my logic. You could not call it and let the GC work harder. It’s my opinion to always have control of what you use and what you can dispose.

Acumatica Cache clearing is exactly what you are addressing by invoking it

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved