typdef struct _structname
{
int x;
string y;
} structure_name;
structure_name variable;
Now I access variable.x
and y
. After using it how can i deallocate or free the memory used by variable
?
Actually the memory is getting allocated when i am doing variable.y="sample string".So the = operator allocates memory which is causing issue. how can i resolve it now?
You've allocated the structure on the stack. The memory it's using will be freed when it goes out of scope. If you want to have control over when the memory is freed theh you should investigate dynamic memory allocation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With