Question

Is it possible to think to have in future an automatic garbage collector in Delphi? There are many applications in which a higly detailed control on when to free an object is not so important and it is just an extra thing to care about.

For such applications having a kind of garbage collector that works like java's one would be interesting.

It could be set in the project options.

Will this possible or not?

Note: I don't mean to manually create it like explained here, I really mean a Delphi feature.

Stated in another way: is it possible to set FastMM to act as Garbage collector?

Was it helpful?

Solution

Garbage collection is possible in C and C++, so I see no reason why Delphi couldn't also have such a feature. If you cross your fingers and wait long enough, Delphi might get garbage collection. I don't see it as a priority for Embarcadero, though.

You can't set FastMM to act as a garbage collector because FastMM doesn't do garbage collection, so there's nothing to set. Delphi's hypothetical future garbage-collection feature would probably have to cooperate with the memory manager, so if such a feature ever exists, and FastMM is still the memory manager at that time, then FastMM will probably gain some settings.

OTHER TIPS

There are many applications in which a higly detailed control on when to free an object is not so important and it is just an extra thing to care about.

I believe there are almost none such applications. Most of the times you think you don't require a control on when your objects are destroyed, you're potentially introducing a bug.

Now, there indeed are cases when certain objects can be safely ignored to later be dealt with by automatic collector. But keep in mind that you need to think this through for every object you're planning on not destroying manually. What if it holds some locks? What if it has some files open, maybe in share-deny mode?

There's not much of a benefit in freeing you from thinking about destroying every object, when to program safely you still need to think about destroying every object.

The purpose of garbage collectors is not to free programmers from seeing this stuff through. It's to save a bit on reference counting and try/finally calls.

you have both pros and cons with garbage collection i thing delphi is good even without GC(garbage collector). even delphi apps take less memory size than managed .net apps , some times garbage collection also slow down the process because it has to find the unwanted resources , confirm whether they are needed again and delete it.if it needed again it has to load again( app becomes slow) or an error there so delphi is good without GC manually freeing is good for a professional programmer

lasted versions of delphi coming with RTTI (this is also a reason for the big size of apps) i think rtti(Runtime Type Information) can help us in future . because it hold some informations about the process going on so i think may be in future some similar function like garbage collector is possible but not sure

but delphi for dot net 2007 and other old delphi dot net have garbage collector + vcl but now deprecated (the garbage collector also dont work 100% well)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top