Board index » delphi » Grabage collector emulation under Win32

Grabage collector emulation under Win32


2005-04-21 05:42:40 AM
delphi250
Another developer is building the code necesary to put MUTIS (a
Delphi.NET library) under Win32. Rigth now, all code asume garbage
collector is present.
I want a elegant&safe solution to have this code under both plataform.
We are building a portable code layer to talk to NET&DelphiWin32
specific thing and the 80% rest of the code is only MUTIS.
(Ps. If you want see cvs.sourceforge.net/viewcvs.py/mutis/Mutis/src/)
A lot are only information.... but some are big classes with lot of
subojects...
How accomplish this? My first inclination is simply declare a ancestor
to all objects (the vast mayority decend from TObject) like
TInterfacedObject... and I assume this cover the issue. Obviously, i put
the necesary destructor code, but I am forgetting something??
--
Mutis: The open source indexing/search engine for Delphi
mutis.sourceforge.net/
(Alpha stage: Developers Wanted!)
 
 

Re:Grabage collector emulation under Win32

"mamcx" wrote
Quote
NET library) under Win32. Rigth now, all code asume garbage
collector is present.
It will be much easier to make all code assume garbage collection is not
present. .NET garbage collection is not at all the same as reference
counting, which is what TInterfacedObject gets you.
bobD
 

Re:Grabage collector emulation under Win32

Quote
It will be much easier to make all code assume garbage collection is not
present. .NET garbage collection is not at all the same as reference
counting, which is what TInterfacedObject gets you.
agreed
besides that if you will be using class references there won't be any
reference counting
also note that using an object reference + it is interface reference can be
dangerous
ex:
var
o: TSomeObject;
begin
o:=TSomeObject.Create;
(o as ISomeInterface).SomeMethod;
// here o is invalid since it is ref cournt was incremented and
decremented to 0 and got destroyed
as a workaround you could have the same scope interface var (i:
ISomeInterface := o as ISomeInterface)