Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost shared_ptr get owner count

I'm using boost::shared_ptr to store a pointer to texture. I'm loading new textures as i need and share them among the program using shared_ptr. If my app is using too much memory i want to remove unused textures to clear memory. Is there a way I can determine how many objects are having access to the texture via shared_ptr ?

like image 880
Andrew Avatar asked Dec 27 '22 13:12

Andrew


2 Answers

If it's unused then the shared_ptr will free it automatically. That's the point of shared_ptr. If you are holding a shared_ptr to a texture without actually using it, then you're violating the contract of shared_ptr and should not be using it.

like image 113
Puppy Avatar answered Jan 05 '23 18:01

Puppy


You can use shared_ptr::use_count(), but read the documentation before doing so!

like image 30
Nicola Musatti Avatar answered Jan 05 '23 16:01

Nicola Musatti