Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using the shared_ptr and declaring as
std::shared_ptr<classa>ptr = std::make_shared<classa>();

So when ever i want to use i am directly calling the pointer and using in the methods.
by using pointer like this memory increases for every call from the method.
I see memory increases in Taskmanager.


Can anyone help me how can i release memory or delete/reset the pointer in/after the function call?


Thanks for the help!!

What I have tried:

1. I have tried resetting the pointer after the function call by ptr.reset();
2. making it as weak_ptr
3. making singleton
Posted
Updated 24-Mar-17 2:15am
v2
Comments
Jochen Arndt 24-Mar-17 8:31am    
This can't be answered without seeing the use of the shared_ptr.

You can set a break point inside the classa destructor to see when it gets deleted. If that never happens there will be still shared_ptr(s) owning the object.
N.Ravi Raj 24-Mar-17 9:24am    
i am deleting the shared_ptr only in destructor.
Jochen Arndt 24-Mar-17 9:39am    
You delete a shared_ptr?
shared_ptr has been introduced to avoid manual deletes because they track the usage and delete when not referenced anymore.

You should really show us the relevant code snippets.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900