现在的位置: 首页 > 综合 > 正文

cocos2d-x节点(CCAutoreleasePool.h)API

2014年01月14日 ⁄ 综合 ⁄ 共 1924字 ⁄ 字号 评论关闭

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-x节点(CCAutoreleasePool.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

如果你希望使用自动释放池,那么你就可以参考他了

///\cocos2d-x-3.0alpha0\cocos2dx\cocoa
//如果你希望使用自动释放池,那么你就可以参考他了

#ifndef __AUTORELEASEPOOL_H__
#define __AUTORELEASEPOOL_H__

#include "CCObject.h"
#include "CCArray.h"

NS_CC_BEGIN

/**
 * @addtogroup base_nodes
 * @{
 */

class CC_DLL AutoreleasePool : public Object
{
    /**
     * 对象池,管理在 array 里面的底层对象
     *
     * 虽然一旦对象被添加,对象池 Array 都保留该对象,适当的调用 Object::release() 可以确保,对象池里面的引用计数不受影响
     * 如果 object 在对象池 array 里,不恰当的 object 释放,可以破坏对象池 array 里正常的 Object::release() 事件
     */
    Array   *_managedObjectArray;
public:
    /**
     * @js NA
     * @lua NA
     */
    AutoreleasePool();
    /**
     * @js NA
     * @lua NA
     */
    ~AutoreleasePool();

    /**
     * Add 将给定的对象添加到 pool 里面.
     *
     * 相同的对象多次添加到相同的对象 pool ,当 对象 pool 被破坏后,每次加入 object 时,object's 都会调用 Object::release()方法
     *
     * @param object    添加到对象 pool 里面的对象.
     * @js NA
     * @lua NA
     */
    void addObject(Object *object);

    /**
     *把给定的对象从对象 pool 里面移除
     *
     * @param object    即将从对象 pool 里面移除的对象.
     * @js NA
     * @lua NA
     */
    void removeObject(Object *object);

    /**
     * 清除 autorelease pool.
     *
     *每次对象被添加到对象 pool 里时都会调用 Object::release() 
     * @js NA
     * @lua NA
     */
    void clear();
};

class CC_DLL PoolManager
{
    Array           *_releasePoolStack;
    AutoreleasePool *_curReleasePool;

    AutoreleasePool *getCurReleasePool();
public:
    /**
     * @js NA
     * @lua NA
     */
    static PoolManager* sharedPoolManager();
    /**
     * @js NA
     * @lua NA
     */
    static void purgePoolManager();
    /**
     * @js NA
     * @lua NA
     */
    PoolManager();
    /**
     * @js NA
     * @lua NA
     */
    ~PoolManager();

    /**
     * 清除堆栈里面的所有 AutoreleasePool
     * @js NA
     * @lua NA
     */
    void finalize();

    /**
     * Push 一个新的 AutoreleasePool 到 pool stack.
     * @js NA
     * @lua NA
     */
    void push();

    /**
     * 从 pool stack 弹出一个 AutoreleasePool.
     *
     * 这个方法确保至少有一个 AutoreleasePool 在 stack 上
     *
     * stack 被破坏时 AutoreleasePool 会弹出
     * @js NA
     * @lua NA
     */
    void pop();

    /**
     * *从当前的 autorelease 池移除一个给定的对象。
     *
     * @param object    要删除的对象。
     *
     * @see AutoreleasePool::removeObject
     * @js NA
     * @lua NA
     */
    void removeObject(Object *object);

    /**
     * 把一个给定的对象添加到当前autorelease池。
     *
     * @param object   要添加的对象。
     *
     * @see AutoreleasePool::addObject
     * @js NA
     * @lua NA
     */
    void addObject(Object *object);
    /**
     * @js NA
     * @lua NA
     */
    friend class AutoreleasePool;
};

// end of base_nodes group
/// @}

NS_CC_END

#endif //__AUTORELEASEPOOL_H__

抱歉!评论已关闭.