Class CC_DLL AutoreleasePool {public: // create an object pool for storing ref and put it into the PoolManager Object pool manager AutoreleasePool (); // create an object pool for storing ref, put it in the PoolManager Object pool manager, and take the name AutoreleasePool (const std: string & name );~ AutoreleasePool (); // Add a ref object to the object pool void addObject (Ref * object); // cyclically traverse the container and call release for the ref object in the container, and finally clear the container, set _ isClearing to true // (call the release function to reduce the count by 1. If the count is 0, delete the object. // For example, if we create an object pool with a value of 1 and add it to the object pool, add 1 to 2 when adding the field to the scenario. // before the end of the frame, traverse the objects in the object pool, call the release function to reduce the number of each created genie by 1, // Delete the genie when the value is 0, and then clear the object pool to prepare for storing the created objects, cycle) void clear (); # if defined (COCOS2D_DEBUG) & (COCOS2D_DEBUG> 0) // determine whether bool isClearing () const {return _ isClearing ;}; # endif // determine whether the ref object bool contains (Ref * object) const exists in the container; // void dump () for debugging; private: // The container that stores the object. Do not forget to traverse the element before the end of each frame to make it call release. Finally, the container is cleared with std: vector <Ref *> _ ManagedObjectArray; // The pool name. It seems useless... Std: string _ name; # if defined (COCOS2D_DEBUG) & (COCOS2D_DEBUG> 0) bool _ isClearing; # endif}; class CC_DLL PoolManager {public: CC_DEPRECATED_ATTRIBUTE static PoolManager * sharedPoolManager () {return getInstance ();} // if it is NULL, create an object pool manager and create an object pool static PoolManager * getInstance (); CC_DEPRECATED_ATTRIBUTE static void purgePoolManager () {destroyInstance ();} static void destroyInstance (); // obtain the current Au ToreleasePool Object pool. Do not forget to store the ref object AutoreleasePool * getCurrentPool () const in AutoreleasePool; // whether the object bool isObjectInPools (Ref * obj) const exists in the object pool manager; // you can call the private member or function of AutoreleasePool ..) Friend class AutoreleasePool; private: PoolManager ();~ PoolManager (); // add and delete the void push (AutoreleasePool * pool) of the Object pool; void pop (); // single-instance static PoolManager * s_singleInstance of the Object pool manager; // The container std: deque <AutoreleasePool *> _ releasePoolStack for storing the object pool; // The current Object pool AutoreleasePool * _ curReleasePool ;};
I don't know if I have been considerate. I seem to have found a bug in CCAutoreleasePool. poolManager * PoolManager: getInstance () {if (s_singleInstance = nullptr) {s_singleInstance = new PoolManager (); // Add the first auto release pools_singleInstance-> _ curReleasePool = new AutoreleasePool ("cocos2d autorelease pool"); // s_singleInstance-> _ releasePoolStack. push_back (s_singleInstance-> _ curReleasePool); // added 2nd times} return s_singleInstance;} PoolManage R ::~ PoolManager () {CCLOGINFO ("deallocing PoolManager: % p", this); while (! _ ReleasePoolStack. empty () {AutoreleasePool * pool = _ releasePoolStack. back (); // _ releasePoolStack. pop_back (); deleted two delete pools;} if it runs properly, however, if I create an AutoreleasePool * a = new AutoreleasePool ("a") in my code, an error will be reported. How can I not use a custom object, as a result, I found a problem in the Code. After commenting on the two sections of code, I can add the AutoreleasePool object in the code.