C++ API cannot release resource
Posted: 29 Jul 2014, 08:51
Description:
Call the below code for about 120 times, the system resource used up:
lg_ptrSmartFox=boost::shared_ptr<SmartFox> (new SmartFox());
lg_ptrSmartFox->Version();
Why I create the SmartFox instance for so many times? --- Because when a connection attempt failed or lost, I will automatically create a new SmartFox instance and reconnect to server.
I noticed, after calling lg_ptrSmartFox->Version(), the use_count increased to 8, and never decrease, the old SmartFox instance cannot be destroyed even giving a new SmartFox pointer. I investigated the source code of C++ API, it seems because of "shared_from_this()" calling inside of SmartFox.
Question:
How to release old SmartFox instance to avoid system resource used up?
Call the below code for about 120 times, the system resource used up:
lg_ptrSmartFox=boost::shared_ptr<SmartFox> (new SmartFox());
lg_ptrSmartFox->Version();
Why I create the SmartFox instance for so many times? --- Because when a connection attempt failed or lost, I will automatically create a new SmartFox instance and reconnect to server.
I noticed, after calling lg_ptrSmartFox->Version(), the use_count increased to 8, and never decrease, the old SmartFox instance cannot be destroyed even giving a new SmartFox pointer. I investigated the source code of C++ API, it seems because of "shared_from_this()" calling inside of SmartFox.
Question:
How to release old SmartFox instance to avoid system resource used up?