C++ memory management of reference types

Posted by Russel on Stack Overflow See other posts from Stack Overflow or by Russel
Published on 2011-01-18T02:06:33Z Indexed on 2011/01/18 2:54 UTC
Read the original article Hit count: 204

Filed under:
|
|
|
|

Hello,

I'm still a fairly novice programmer and I have a question about c++ memory management with refence types.

First of all, my understanding of reference types:

A pointer is put on the stack and the actual data that the pointer points to is created and placed on the heap. Standard arrays and user defined classes are refence types. Is this correct? Second, my main question is do c and c++'s memory management mechanisms (malloc, free and new, delete) always handle this properly and free the memory that a class or array is pointing to? Does everything still work if those pointers get reassigned somehow to other objects of the same size/type on the heap? What if a class has a pointer member that points to another object? I am assuming that delete/freeing the class object doesn't free what it's member pointer points to, is that correct?

Thanks all!

-R

© Stack Overflow or respective owner

Related posts about c++

Related posts about c