Atozed Forums

Full Version: Calling free on objects created and returned by a .net method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
Correct. CT objects are to be treated like normal Delphi objects. You must free them.