Skip to main content

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

 

 

 

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.

 


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


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


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