Atozed Forums
Calling free on objects created and returned by a .net method - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: CrossTalk (https://www.atozed.com/forums/forum-2.html)
+---- Forum: CrossTalk General Discussion (https://www.atozed.com/forums/forum-7.html)
+---- Thread: Calling free on objects created and returned by a .net method (/thread-2601.html)



Calling free on objects created and returned by a .net method - gezaszabo - 12-20-2021

Hi,

I understand that if I create a .net object from Delphi then CrossTalk on the .net side will keep a reference to it until I call free to avoid it being collected by the Garbage Collector.

What happens if the .net object is created and returned by a .net method? Will CrossTalk keep a reference to it until I call free? If so does that means that whenever an object is returned I must call free on it on the Delphi side?

Regards
Geza


RE: Calling free on objects created and returned by a .net method - gezaszabo - 12-21-2021

I have tested this. CrossTalk will keep a reference to it until free is called.

If free is not called then the Delphi Stub is never freed and the .Net object is never garbage collected.


RE: Calling free on objects created and returned by a .net method - kudzu - 01-12-2022

Correct. CT objects are to be treated like normal Delphi objects. You must free them.