[OT] memory management -- was Re: itoa'd you so?
Bryan Sant
bryan.sant at gmail.com
Wed Sep 19 23:20:35 MDT 2007
On 9/19/07, Michael L Torrie <torriem at chem.byu.edu> wrote:
> Manual memory management is often, in my opinion, a huge plus of C and
> C++. With reference-counting smart pointers and destructors, memory
> management in C++ is very straight-forward, fast, and safe. Just
I agree. Using smart pointers makes a big difference.
> understanding a bit about how C++ does scoping, and you can very easily
> build and destroy entire data structures all without a single leak and
> without having to rely on a garbage collector. Not saying a GC is bad;
> simply that it's not always necessary.
I also agree. A proper understanding of memory management does your body good.
> With only a few caveats, C++ programmers can easily move to programming
> in Java and dealing with the GC dropping references right and left. But
> it rarely works the other way. 9/10 core dumps in the BYU CS 240 class
> are because of Java. It pollutes C++ programmers like nothing else!
The problem isn't a high-level language. The problem is dumb BYU CS
students ;-).
> One of the caveats for C++ programmers is the way that C++ guarantees
> destruction when an object goes out of scope, especially when you rely
> on the side effects. Guaranteed destruction doesn't translate directly
> into Java, although the "finalize" keyword can help (if I recall
> correctly). A good article on the idea is at
> http://royontechnology.blogspot.com/2007/01/deterministic-destruction-of-objects-in.html
Finalize actually has its warts. It does provide somewhat of a
nondeterministic destructor, but using it delays your object from
being collected for an extra generation. Not a huge issue, but if you
want better heap control and deterministic clean-up of resources, it's
best to use a standard method that you manually call.
-Bryan
More information about the PLUG
mailing list