@@ -277,16 +277,25 @@ WeakRefPool* WeakRefPool::get() {
277
277
void WeakRefPool::check (CCObject* obj) {
278
278
// if this object's only reference is the WeakRefPool aka only weak
279
279
// references exist to it, then release it
280
- if (obj && m_pool.contains (obj) && obj->retainCount () == 1 ) {
281
- // set delegates to null because those aren't retained!
282
- if (auto input = typeinfo_cast<CCTextInputNode*>(obj)) {
283
- input->m_delegate = nullptr ;
284
- }
285
- obj->release ();
286
- // log::info("nullify {}", m_pool.at(obj).get());
287
- m_pool.at (obj)->m_obj = nullptr ;
288
- m_pool.erase (obj);
280
+ if (obj && obj->retainCount () == 1 ) {
281
+ this ->forget (obj);
282
+ }
283
+ }
284
+
285
+ void WeakRefPool::forget (CCObject* obj) {
286
+ if (!obj || !m_pool.contains (obj)) {
287
+ return ;
289
288
}
289
+
290
+ // set delegates to null because those aren't retained!
291
+ if (auto input = typeinfo_cast<CCTextInputNode*>(obj)) {
292
+ input->m_delegate = nullptr ;
293
+ }
294
+
295
+ obj->release ();
296
+ // log::info("nullify {}", m_pool.at(obj).get());
297
+ m_pool.at (obj)->m_obj = nullptr ;
298
+ m_pool.erase (obj);
290
299
}
291
300
292
301
std::shared_ptr<WeakRefController> WeakRefPool::manage (CCObject* obj) {
@@ -295,7 +304,7 @@ std::shared_ptr<WeakRefController> WeakRefPool::manage(CCObject* obj) {
295
304
}
296
305
297
306
if (!m_pool.contains (obj)) {
298
- CC_SAFE_RETAIN ( obj);
307
+ obj-> retain ( );
299
308
auto controller = std::make_shared<WeakRefController>();
300
309
controller->m_obj = obj;
301
310
m_pool.insert ({ obj, controller });
0 commit comments