Re: ownership problem?



In article <dy8gf.3763$3o6.904548@xxxxxxxxxxxxxxxxxxxxxxxx>,
Jeffrey Schwab <jeff@xxxxxxxxxxxxxxxx> wrote:
....
> Yes it is. Memory is only one type of resource. There are still files
> and sockets to close, pipes to flush, log messages to be printed, GDI
> contexts to free, locks to release, etc. In C++, these things are
> generally done by destructors, which are called automatically and
> deterministically. I am not a Python Guru, but in Perl, Java, and other
> languages that have built-in garbage collectors, these tasks have to be
> done explicitly. I find that this forces a procedural approach, even in
> an otherwise object-oriented program.
>
> If you want something like automatic garbage collection in C++, I
> recommend the use of Factories with destructors that release the
> Factories' products. The zeitgeist in c.l.c++.moderated seems to prefer
> the use of smart (reference-counted) pointers, which also rely on
> destructors to release resources automatically. Plentry of free,
> open-source implementations are available.

You may be gratified to learn that Python's main storage model
is reference counted objects, and when an object falls out of
all referenced scopes its finalizers run immediately.

This is however true only of the C implementation. The Java
implementation naturally has Java's limitations in this matter,
so documentation generally avoids the issue. The C implementation
has been around for over a decade, wonder if it had any influence
on your C++ zeitgeist?

Donn Cave, donn@xxxxxxxxxxxxxxxx
.



Relevant Pages

  • Re: VS2005 C#: User Testing
    ... The type or namespace name 'Drawing' does not exist in the namespace ... 'System' (are you missing an assembly reference?) ... Run it again, as now it should find it as a resource, and not be trying ... Studio altogether, not knew to programming. ...
    (microsoft.public.vstudio.general)
  • VS2005 C#: User Testing
    ... The type or namespace name 'Drawing' does not exist in the namespace ... 'System' (are you missing an assembly reference?) ... essentially a sizable hint window. ... Run it again, as now it should find it as a resource, and not be trying ...
    (microsoft.public.vstudio.general)
  • Re: Article of interest: Python pros/cons for the enterprise
    ... create a less flexible Python feature that achieves the ... you can create a temporary object whose reference count will become ... especially in a complex multi-statement scope. ... If you can then request that arbitrary actions be taken automatically when those events happen, you can pair up resource acquisitions and releases very easily. ...
    (comp.lang.python)
  • Re: Messages for a resource are sent to a non-existent account
    ... Exchange Server 2003 a resource account with a calendar. ... reference to her in any address book or as a remaining delegate. ... other cached data there is an invalid reference to Person A, ...
    (microsoft.public.exchange.admin)
  • Re: Destructor: not gauranteed to be called?
    ... memory leak problem, and it probably does a good job at that. ... However, it doesn't provide the tools needed to solve the deterministic resource destruction problem, with the exception of C++/CLI. ... Why do I care about this when the .NET framework has finalizers? ... and C++ programmers know how dangerous it is to use exceptions without proper support for deterministic destructors. ...
    (microsoft.public.dotnet.languages.vc)