以下来自对 cocos2d-x-3.5 的源码分析,今天重点研究它的动态开辟的对象释放问题.
涉及以下3个基本的class
和一个模板类
手动引用计数类
class Ref
Ref
对象池AutoreleasePool
对象池管理员
PoolManager
PoolManager
是单例的 !
static PoolManager* getInstance()
- 池子只能有压栈和退栈两个操作.
void push(AutoreleasePool *pool);
void pop();
- 构造单例时候会自动构造一个
AutoreleasePool
作为当前使用的池子. - 总是使用栈顶的池子.
模板类
RefPtr
模拟shared_ptr
另外还有一个相关的class : class Clonable
.
* 支持接口 Clonable* clone()
,会复制Ref
,重新开始计数.
可以看到 cocos2d-x 提供了基本的管理机制,但是需要依赖程序员的自觉性!!!
基于Ref的继承体系速查
Ref
Director
DisplayLinkDirector
EventListener
EventListenerAcceleration
EventListenerController
EventListenerCustom
EventListenerFocus
EventListenerKeyboard
EventListenerMouse
EventListenerTouchOneByOne
Event
EventDispatcher
EventController
EventFocus
EventCustom
EventKeyboard
EventMouse
EventTouch
Scheduler
ScriptHandlerEntry
Touch
ActionManager
Action
:Cloneable
FiniteTimeAction
ActionInstant
StopGrid
ActionInterval
GridAction
Grid3DAction
TiledGrid3DAction
AccelDeccelAmplitude
AccelAmplitude
DeccelAmplitude
ActionEase
EaseBackIn
EaseBackInOut
EaseBackOut
EaseBezierAction
EaseBounce
EaseBounceIn
EaseBounceInOut
EaseCircleActionIn
EaseCircleActionInOut
EaseCircleActionOut
EaseCubicActionIn
EaseCubicActionInOut
Animate
BezierBy
BezierTo
Blink
FadeTo
FadeIn
FadeOut
JumpBy
JumpTo
MoveBy
MoveTo
Repeat
RepeatForever
ReverseTime
RotateBy
RotateTo
ScaleTo
ScaleBy
TintBy
TintTo
TargetedAction
ProgressFromTo
ProgressTo
ActionTween
Sequence
SkewTo
SkewBy
Spawn
Follow
Speed
ActionCamera
OrbitCamera
PointArray
AnimationFrame : Cloneable
Animation : Cloneable
AnimationCache
Node
Camera
BaseLight
AmbientLight
DirectionLight
PointLight
SpotLight
AtlasNode
LabelAtlas
:LabelProtocol
TileMapAtlas
ClippingNode
ClippingRectangleNode
DrawNode
TMXLayer
TMXTiledMap
LabelTTF
:LabelProtocol
,BlendProtocol
LabelBMFont
:LabelProtocol
,BlendProtocol
Layer
LayerMultiplex
LayerColor
:BlendProtocol
LayerGradient
Menu
MenuItem
ImageView
MenuItemSprite
MenuItemToggle
MenuItemLabel
MenuItemAtlasFont
MenuItemFont
MenuItemFont
MotionStreak
:TextureProtocol
NodeGrid
RenderTexture
ParallaxNode
ProtectedNode
ParticleBatchNode
:TextureProtocol
ParticleSystem
:TextureProtocol
ParticleSystemQuad
ParticleExplosion
ParticleMeteor
ParticleFire
ParticleFireworks
ParticleFlower
ParticleGalaxy
ParticleRain
ParticleSmoke
ParticleSnow
ParticleSpiral
ParticleSun
Scene
TransitionScene
TransitionCrossFade
TransitionFade
TransitionJumpZoom
TransitionShrinkGrow
:TransitionEaseScene
TransitionMoveInL
:TransitionEaseScene
TransitionMoveInB
TransitionMoveInR
TransitionMoveInT
TransitionSceneOriented
TransitionFlipAngular
TransitionFlipX
TransitionFlipY
TransitionZoomFlipX
TransitionZoomFlipY
TransitionFadeTR
:TransitionEaseScene
TransitionFadeDown
TransitionFadeUp
TransitionSlideInL
:TransitionEaseScene
TransitionSlideInR
TransitionSlideInT
TransitionSplitCols
:TransitionEaseScene
TransitionSplitRows
TransitionTurnOffTiles
TransitionPageTurn
TransitionProgress
Sprite
:TextureProtocol
SpriteBatchNode
:TextureProtocol
TMXLayer
TMXTiledMap
Component
FontCharMap
FontFNT
FontFreeType
LayoutComponent
FontAtlas
Grabber
GridBase
Grid3D
TiledGrid3D
SpriteFrame
:Clonable
SpriteFrameCache
TMXObjectGroup
TMXLayerInfo
LayoutManager
RichElement
GLView