Board index » delphi » Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection


2005-08-09 11:36:04 PM
delphi119
It would be very nice of Delphi was reimplemented so that it features
memory management just like the D language is utilizing: Garbage
collection is the default, but never imposed. This gives ease of use to
those that wish to have garbage collection, but also allows programmers
to manage their own memory if the programmer wishes. The syntax by
which this is accomplished could be worked out easily enough. If the
application were compiled for Win32 then the optional garbage collector
would be included by the linker if it were required, or excluded if the
application did not utilize it. Likewise, if the application were
compiled for .NET and did not feature any programmer-managed memory
allocations then the application would be compiled as a pure .NET app;
otherwise it would be compiled much as the C++.NET apps are. The Win32
& .NET programmers would then be able to share most of their code
without having to rewrite the management code.
The syntax could be something like:
MyButton := TButton.Create; // programmer will manage memory
MyButton := new TButton.Create; // relies on garbage collection
That would offer backwards-compliance, but if we are willing to go for
the more "logical route", then perhaps backwards compliance should be
broken and switch the meanings:
MyButton := TButton.Create; // garbage collected object
MyButton := new TButton.Create; // programmer-managed object
Either way, there should be two ways of allocating an object: one for
defaulting it to the garbage collector, and one for letting the
programmer manage it.
 
 

Re:Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

"Mike Vance" <XXXX@XXXXX.COM>writes
Quote
It would be very nice of Delphi was reimplemented so that it features
memory management just like the D language is utilizing: Garbage
collection is the default, but never imposed.
I rather prefer Borland R&D spend the resources on win64, .NET 2.0, CF and
the many other area's we want covered.
Quote
The Win32
& .NET programmers would then be able to share most of their code
without having to rewrite the management code.
I do that already today with only very few IFDEF's.
Regards
Uffe
 

Re:Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

Hi!
Quote
It would be very nice of Delphi was reimplemented so that it features
memory management just like the D language is utilizing: Garbage
collection is the default, but never imposed. This gives ease of use to
those that wish to have garbage collection, but also allows programmers
to manage their own memory if the programmer wishes. The syntax by
That feature is called: Mixed code compiler.
And yes, programming is all about freedom :)
Best Regards!
Atmapuri
 

Re:Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

I sorta thought the DotNet version already was an optional garbage
collector, if you used VCL.NET I mean. With VCL.NET, can not you either
free/dispose everything yourself via the "normal" way, or let the garbage
collector get it when it wants?
-BKN
 

Re:Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

Bryce,
Quote
I sorta thought the DotNet version already was an optional garbage
collector, if you used VCL.NET I mean. With VCL.NET, can not you either
free/dispose everything yourself via the "normal" way, or let the garbage
collector get it when it wants?

-BKN
Hi Bryce,
it's not free-ing, it is disposing. And actually, you have to, it is not
optional as there are unmanaged resources involved for which GC has no
clue what to do with.
If you know, that a specific VCL.Net does not use unmaged stuff, you
don't need to dispose it. Even if you did, it wouldn't "free" the
object. ;-)
Please correct me, if this was wrong, I am not that familiar with VCL.Net...
 

Re:Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

I writes:
Quote

If you know, that a specific VCL.Net does

This should read "VCL.Net class"...
 

Re:Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

Robert Giesecke writes:
Quote


Hi Bryce,
it's not free-ing, it is disposing. And actually, you have to, it is not
optional as there are unmanaged resources involved for which GC has no
clue what to do with.
If you know, that a specific VCL.Net does not use unmaged stuff, you
don't need to dispose it. Even if you did, it wouldn't "free" the
object. ;-)
Please correct me, if this was wrong, I am not that familiar with VCL.Net...
You're wrong. If you did not free the item the GC would eventually free up the
object (and the object would free up the unmanaged resources). The reason to
call Free on items with unmanaged resources when you are done is because it
makes sense to release the limited resources as soon as possible instead on some
unknown time in the future when the GC will get around to it.
--
Jeff Overcash (TeamB) On waves of silver I dreamed of gold
(Please do not email 'Till I lost the peace that dreaming gives
me directly unless I dreamed of the moment of my own death
asked. Thank You) That no one ever dreams and lives (Marillion)
 

Re:Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

Jeff Overcash (TeamB) writes:
Quote

You're wrong. If you did not free the item the GC would eventually free up the
object (and the object would free up the unmanaged resources).

This would need a finalizer, costing additional cycles on a GC sweep.
Finalizers should be avoided, IMHO, for this very reason.
If you know specifics of VCL.Net's internals I would be very interested in
it. Maybe I will run Reflector against it. ;-)
Quote

The reason to call Free on items with unmanaged resources when you
are done is because it
makes sense to release the limited resources as soon as possible instead on some
unknown time in the future when the GC will get around to it.

This might be true for VCL.Net (as I said I am not that familiar with it).
Without finalizers freeing unmanged resources, you will get a mem leak.
IDisposable gets very "seductive" in these cases, though it does require
a call to Dispose. (or Free in D.Net) ;)
A known example for mem leaks caused by carelessly handled unmanaged
resources is Oracle's data provider, in particular it is ref cursors.
@Topic
I would love a GC in native Delphi as I would love a multipass compiler,
unnamed contructors/destructors, Reflection and attributes. ;-)
But I doubt we will see things like this... :-(
 

Re:Delphi32 & Delphi.NET Should Both Have *Optional* Garbage Collection

"Robert Giesecke" <XXXX@XXXXX.COM>writes news:42f93857
Quote
This might be true for VCL.Net (as I said I am not that familiar with it).
Without finalizers freeing unmanged resources, you will get a mem leak.
IDisposable gets very "seductive" in these cases, though it does require
a call to Dispose. (or Free in D.Net) ;)
A known example for mem leaks caused by carelessly handled unmanaged
resources is Oracle's data provider, in particular it is ref cursors.
Eric Grange has articulated the critique of the .NET GC many times. Here's
a good thread.
groups-beta.google.com/group/borland.public.delphi.non-technical/browse_thread/thread/dc32755a64af17d0/87ec8323d9158915
Quote

@Topic
I would love a GC in native Delphi as I would love a multipass compiler,
unnamed contructors/destructors, Reflection and attributes. ;-)
But I doubt we will see things like this... :-(
God, I hope not.
I have no use for a GC, and have no trouble freeing my own resources.
-- d
---------------------------------------------------
Need to see what's happening?
Check out the Delphi Community Blog Aggregator
delphi.flashblogger.com