Skip to main content
Solved

Recursive calls to a method which creates a graph instance

  • 30 November 2022
  • 4 replies
  • 272 views

Joe Schmucker
Captain II
Forum|alt.badge.img+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

 

 

 

Best answer by Leonardo Justiniano

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.

 

View original
Did this topic help you find an answer to your question?

4 replies

Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+5

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.

 


Forum|alt.badge.img+5
  • Captain II
  • 499 replies
  • November 30, 2022

@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<>()? 


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • 443 replies
  • November 30, 2022
ddunn wrote:

@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.


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+5

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings