在Cocos2d中,如何从OpenGL内存(GPU)中释放纹理?
CCSprite *sprite;
sprite.texture = [[CCTextureCache sharedTextureCache] addImage: @"mySpriteImage.png"];
sprite.position = ccp(width/2.0f, height/2.0f);
[self addChild:sprite z:2 tag:kTagMySprite];
...
[sprite removeFromParentAndCleanup:YES];
上面的代码是否存在内存泄漏? OpenGL纹理是否被释放,或者是否需要从缓存中释放?
CCSprite *sprite;
sprite.texture = [[CCTextureCache sharedTextureCache] addImage: @"mySpriteImage.png"];
sprite.position = ccp(width/2.0f, height/2.0f);
[self addChild:sprite z:2 tag:kTagMySprite];
...
[sprite removeFromParentAndCleanup:YES];
Is there a memory leak in the code above? Is the OpenGL texture released, or does it need to be released from the cache?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大多数问题都可以通过使用正确的工具来回答。在这种情况下,stackoverflow 不是一个合适的工具。 仪器是。
您还可以使用 Vulcan 逻辑来解决这个问题。这段代码正在被全球数以千计的开发人员使用。对于已经存在的软件库,必须考虑此代码导致内存泄漏的概率infinitesimal 3年多了。
Most questions can be answered by using the right tool. In this case, stackoverflow is not the tool. Instruments is.
You can also approach this with Vulcan logic. This piece of code is being used by thousands of developers worldwide. The probability of this code causing a memory leak has to be considered infinitesimal for a software library that has existed for over 3 years.
我得到了解决方案,其中一个调用从 CCTextureCache 中删除纹理,并删除 OpenGL 纹理 (glGenTextures id) 。
I got solution, One of these call removes texture from
CCTextureCache
and that removes OpenGL texture (glGenTextures id) .