Clear Datatable Question - Memory Consumption

Curious if its a good practice to clear DTs when they their contents is no longer needed.

I have a use case where I’m consuming, at times, a CSV that can range from 100,000 to 500,000+ rows. I go through a couple of intermediate DTs trimming, sorting, uniquing. Once I get my final “data set” I don’t need the primary DT anymore.

I guess my primary question is when DTs are cleared of data, is the memory they used released back to Windows or made available within Studio/Robot for other purposes ?

Hi,

If we call DataTable.Clear,Gabage collector will release actual memory in the best time.
If we need to release it immediately, we can use GC.Collect method.

The following will also help you.

Regards,

1 Like

Hey @riverrat437 !! In cases where there is a lot of memory crash it is interesting to clear garbage. But it is extremely important that you have a well modularized code in .xaml’s and control the scope of your variables, so the memory buffer allocated to them will be freed when you leave that context. So you will rarely have memory problems.

Hope it helps!!

Oh that is nice to know. Thank you you for the reply.

My struggle with context is it has actually gotten me in trouble in the past. I actually found a latent logic issue cause by a variable context issue. I understand variable context and its benefits (conceptually outside of your helpful reply) but I’m skeptical because of how UiPath lets you create variable context issues without realizing it. In my experience, tt goes somewhat to when you create variable in your workflow’s life cycle as you develop it. Regard less of that, thank you for your reply. It is helpful.

Hey @gabrielribas4, I thought about your comment a bit more.

Something I hadn’t considered before is putting my data acquisition / manipulation activities into a child workflow. The child would return the data that I need as a OUT argument. Since the datatables are in the child context, that would allow the memory buffer allocated to it (and the large datable or two) to be freed at some point when the child is exited.

Thank you for the rely.

1 Like

This is the point, @riverrat437 !!! You’re welcome! Any other questions, bring them to us here on the forum!

If you can please mark any answer in this thread as a solution. Thanks!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.