Global memory life state

[font=“Comic Sans MS”]
In my program after assigning some value to the pointer ( dev_ptr) kernal is launched, then after calculation i free the memory of dev_ptr [ with the help of cudaFree(dev_ptr) ],

But even after memory deletion I am able to access the same dev_ptr value,

Is this means that global memory exist during the life time of a program.

Please help :confused:

Note: Required file are attached …

Accessing device memory after freeing it has undefined behavior. Undefined does not necessarily mean immediate failure. The memory is not zeroed out, and it is quite possible the memory controller will not even notice the illegal access. If you allocate more device memory, this space might be reused.

You should, of course, not access freed memory on purpose. :)

[font=“Times New Roman”]Actually my requirement is to allocate memory say for pointer e.g d_a,d_b,d_c ( after memory allocation this might be possible that whole of the global memory might be in use) , after one kernel launch I would like to free d_a ( as global memory might be full) but keep d_b,d_c for reuse & again want to launch kernal to calculate other pointer e.g d_e.

So is the above case possible so that before the second kernal Launch global memory got free to accommodate the new pointer or is there any other work around.

Thanks in advance. [/font]

Is there any method to make sure that pointer to global memory is free or not.

You don’t need to do anything special here. After you free d_a, don’t use the address in that pointer variable again. You are free to allocate more memory later and store the address in d_e. The driver will use whatever memory is available, including space that used to be pointed at by d_a.

Thanks for your time…