|
![](/i/fill.gif) |
On 3/13/2012 6:11 AM, Invisible wrote:
> I was eventually able to get the program to produce the correct output.
> However, it uses the dreaded "new" operator. In particular, it does
> /not/ use the "delete" operator anywhere. In other words, it leaks. I
> have literally no idea how to fix this. I can't think of any way of
> doing it that won't result in double-freeing objects. That's mainly
> because I can't put responsibility for object creation (and hence object
> destruction) in the logical place. And /that/ is because I don't have
> some of the necessary technical understanding.
>
> I found a reasonable C++ introduction at cplusplus.com, but it doesn't
> explain several technical points which I'm unclear on. Does anybody know
> of a better resource? (Obviously, a Google search will turn up millions
> of results. It's hard to know which ones are /good/ resources, however.)
Good memory management in C and C++ are things you really have to learn
as you go along. You can probably encapsulate your heap object pointers
into a handler class, but you probably have some learning to go before
you're ready to implement that.
I think the best way to go is to decide whether a given pointer
represents an object that is created on the heap and is owned by the
pointer's container, or if it just refers to an object that is owned by
some other container. The owner takes care of deleting its objects
created on the heap, but otherwise objects get left alone.
> (Is it just me? "Net Beans"? It's an IDE. What the /hell/ does that have
> to do with networking? The "beans" part I kinda get; everything
> Java-related has to be themed on coffee or coffee beans. But why "net"?)
Apparently Java's developers are focused on its Web capabilities, and
are trying to emphasize that.
Regards,
John
Post a reply to this message
|
![](/i/fill.gif) |