[OT] memory management -- was Re: itoa'd you so?

Michael L Torrie torriem at chem.byu.edu
Wed Sep 19 17:10:09 MDT 2007

Bryan Sant wrote:
> Oh the joys of life with manual memory management :-)

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
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.

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!
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

It's always fun to catch java-isms in C or C++ code, the most prominent
one is the "type var = new type" expression, which is often used where a
 static declaration would be far better (in C or C++).  Of course using
smart pointers (reference-counting objects that hold a pointer), the
paradigm for use is much more java-like.

> -Bryan
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */

More information about the PLUG mailing list