I’ve developed an activity for UiPath that takes a DataTable as input.
I’m uncertain whether the original DataTable data object is passed to my activity or if a new data object is created.
To enhance the performance of my activity, I set the original DataTable to null after a pont where its not needed, indicating the garbage collector to reclaim memory from the unused data. Since my activity doesn’t return any data, my concern is whether the original data object is still accessible. If developers intend to use that DataTable later in the code, it might cause issues as the data object could be removed by the garbage collector due to my activity setting the DataTable to null.
When you pass a DataTable as an input to your UiPath activity, the original DataTable object is passed by reference, not by value. This means your activity operates directly on the same DataTable provided as input, without creating a new object. Therefore, setting the original DataTable to null inside your activity affects the DataTable object outside of it. This action can lead to issues if the DataTable is intended for use later in the workflow. To avoid unintended consequences, refrain from modifying input arguments in a way that may impact their usability outside the activity. Instead of setting the DataTable to null, let it go out of scope naturally when no longer needed. The .NET garbage collector will reclaim its memory once it’s no longer reachable, ensuring the DataTable remains accessible and usable elsewhere in the workflow without unexpected behavior.
b = a; // 'b' is now pointing to the same address as 'a'
If I set b = null, it merely removes the pointer/reference to that data object. However, ‘a’ still retains the reference to the data object 10.
This concept applies similarly to my activity. Your response seems different from this logic, but I believe I am heading in the right direction. Please correct me if I’m wrong.
In my activity’s logic, let’s say UiPath passed a variable called ‘dt’ containing a data object of a DataTable. My activity takes an InArgument named ‘userDatatable’:
userDatatable = dt;
Even if I set ‘userDatatable’ to null, it doesn’t affect ‘dt’ referencing the data object. The real challenge arises in a scenario like this:
a = 10;
b = a;
a = null;
Now, only ‘b’ is holding the reference. If I set ‘b’ to null, there is no reference to the data object, allowing the garbage collector to clear the unused memory.
Since my activity doesn’t return any data, my concern is whether the original data object is still accessible.
I think it’s no problem. Because even if variable inside the activity is set null, just reference of the variable to the memory is cleared and reference of original variable still exists , GC doesn’t clear the memory.
The following post is case of InvokeCode, but works as same logic. This may helps you.