Can't understand if deallocation happens?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 22 05:57:22 PST 2017


On Sunday, 22 January 2017 at 12:49:11 UTC, Suliman wrote:
>     writeln(str_ptr);
> 	
>     writeln("before dealloc: ", str_ptr.length);
>     GC.free(str_ptr.ptr);
>     writeln(str_ptr);

You freed the CONTENTS, but are printing the CONTAINER.

str_ptr.ptr returns exactly the same thing as str.ptr or 
(*str_ptr).ptr, a pointer to the contents. When you write 
str_ptr, you print the pointer to the container.


The container isn't moving, it is a stack variable and not 
managed by GC. If you want to see changes to the content pointer, 
just use it.

string* in D is rarely what you want and I suggest you avoid 
using it until you have a strong grasp on the fundamentals of how 
arrays and pointers work. You're just confusing yourself by 
trying it right now.


> Is it's address from 0 of current App memory?

it is the virtual address space, the app doesn't necessarily use 
all the possible values.


More information about the Digitalmars-d-learn mailing list