cocos2dx3.0 Ref

前端之家收集整理的这篇文章主要介绍了cocos2dx3.0 Ref前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

转自:http://blog.csdn.net/w18767104183/article/details/25876481


cocos2dx中所有对象都继承于Ref,或者继承于 Ref和Clonable
Ref中就是维护了一个计数器,用于判断该继承于Ref的对象是否应该delete

  1. classCC_DLLRef
  2. {
  3. public:
  4. //计数加1
  5. voidretain();
  6. //计数减1,如果为0,删除对象
  7. voidrelease();
  8. //添加到对象池中,别忘了PoolManager(对象池管理器)管理AutoreleasePool(对象池),AutoreleasePool管理Ref
  9. Ref*autorelease();
  10. //得到当前的计数
  11. unsignedintgetReferenceCount()const;
  12. protected:
  13. //创建时计数设为1
  14. Ref();
  15. public:
  16. virtual~Ref();
  17. protected:
  18. ///countofreferences
  19. //计数变量
  20. int_referenceCount;
  21. //友元类
  22. friendclassAutoreleasePool;
  23. #ifCC_ENABLE_SCRIPT_BINDING
  24. ///objectid,ScriptSupportneedpublic_ID
  25. int_ID;
  26. ///Luareferenceid
  27. int_luaID;
  28. #endif
原文链接:https://www.f2er.com/cocos2dx/345688.html

猜你在找的Cocos2d-x相关文章