Cocos2d:粒子.autoRemoveOnFinish不释放内存
我通过以下方式创建粒子效果:
CCParticleSun* p = [[CCParticleSun alloc]initWithTotalParticles:5000];
p.autoRemoveOnFinish = YES;
//more parameters
p.duration = 1;
并将其添加到我的场景中:
[self addChild:p z:self.zOrder+1];
每次创建此粒子效果时,都会分配 3MB 内存,但从未释放。 我做错了什么?我需要手动释放粒子系统吗?
NSZombies 被禁用,因此它不会意外地保留在内存中。
I create a particle effect in the following way:
CCParticleSun* p = [[CCParticleSun alloc]initWithTotalParticles:5000];
p.autoRemoveOnFinish = YES;
//more parameters
p.duration = 1;
and add it to my scene:
[self addChild:p z:self.zOrder+1];
Every time I create this particle effect, 3MB of memory are allocated, but never released.
What am I doing wrong? Do I have to manually release the particle system?
NSZombies are disabled, so it's not kept in memory by accident.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您分配(或保留)的所有内容也必须释放。对于Cocos2D,最简单的方法是将其变成一个自动释放对象,如下所示:
然后它会在Cocos2D 清理场景后被释放。
PS: 5000 个粒子是一个巨大的粒子量!难怪您会看到大小为几兆字节的分配。最多尝试500,
如果您使用大约 32x32 像素或更大的粒子纹理,则为 100 或更少。
Everything you alloc (or retain) you have to release as well. For Cocos2D it's easiest to turn it into an autorelease object like this:
Then it will be released after Cocos2D cleans up your scene.
PS: 5000 particles is a GIGANTIC amount of particles! No wonder you're seeing allocations of several megabytes in size. Try going for 500 at most,
100 or less if you're using particle textures that are about 32x32 pixels or greater.