views:

157

answers:

5

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?

+7  A: 

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.

himself
yes for sure, but that said having a garbage collector as an option is not a bad thing.
A: 

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

Vibeeshan
d2010 and xe already have rtti but not garbage collector
Vibeeshan
c++ and c already have garbage collector because they use rtti
Vibeeshan
Vibeeshan
+5  A: 

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.

Rob Kennedy
A: 

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)

Vibeeshan
Are you saying .NET GC doesn't work 100% well? Delphi.NET outputs CLR code, and the GC is the .NET GC, not a Delphi.NET own GC.
ldsandon
hey delphi vcls have some memory leaks that cannot even identified by .net's gc. delphi for dot net (d2007 and oldies ) are just a .net wrraped vcl so you cant expect more than vcl
Vibeeshan
+1  A: 

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

Vibeeshan
yes my first concern was that in delphi there is much to type like "begin" instead of "{", up to Free the objects. Of course freeing the objects gives you full control and forces you to think more on object lifespan. Then, anyway I don't think developers spend more than 5% of their time in actually typing new lines of code, so it is not a real issue.
Yes, you waste a little time typing begin (and code completion does for you a lot of times), and gain a lot of time while reading code where spotting begin/end blocks is much easier than {/} ones
ldsandon
I type `begin` and `end` a lot faster than those terrible `{` and `}` for which you need the shift and [] keys.
The_Fox
Well, on the upside, while there is a bit more to type, there is a whole lot less to debug :-)
Marco van de Voort