请教,cocos2dx如何渲染1000帧的序列,如何清理内存

1000帧只是为了方便表述,实际情况是这样:

我从摄像头读取视频数据转换为UIImage(iOS平台),再将UIImage转为CCSprite,并显示出来,
然后每隔0.1秒移除上一个CCSprite,重新从UIImage创建一个CCSprite并显示出来。
我用Sprite->removeFromParentAndCleanup(true) 来移除精灵,但是遇到了问题,内存飙升很快,程序在执行几秒后就奔溃了。
(这里的Sprite是实时产生,动画序列可以看作无限长)
请问各位大大是否有解决这个问题的办法或者思路?万分感谢!

现在步骤是:UIImage 生成 Texture2d 生成 Sprite ,每帧移除上一个sprite,新创建一个sprite加入场景,

问题还是没解决,运行不到十秒就崩溃

这是UIImage转Sprite方法:

cocos2d::Sprite *getSpriteFromUIImage(UIImage *img)
{
// First get the image into your data buffer
CGImageRef imageRef =
![](;
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char rawData = (unsigned char) calloc(height * width * 4, sizeof(unsigned char));
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);

CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);


/* create a texture with the raw data, and use that to create a CCSprite*/
Texture2D *tempTexture = new Texture2D();
tempTexture->initWithData(rawData,
                          4 * width * height,
                          Texture2D::PixelFormat::RGBA8888,
                          width, height,
                          cocos2d::Size(width, height));

tempTexture->autorelease();
cocos2d::Sprite *finalSprite = cocos2d::Sprite::createWithTexture(tempTexture);

free(rawData);

return finalSprite;

}

加上
tempTexture->autorelease();不崩了,低级错误。

但是这种方式效率和视频质量都有问题。

)

=。=。。。要removetexture 话说 这个想法 简直奇葩。。。

问题没解决,有其它方法吗?

lz是想播放视频啊。。

这种0.1s/帧播图的方式还是省省吧- -

真想搞的话
1.试试搞个缓存,先读个1000张图片到内存,然后边播放边加载
2.尽量降低图片分辨率,别弄个2M/张的高清图来播
3.适当放慢速度,0.2s/帧放放看,会不会爆

视频分辨率是480*360的,在iphone4s上可以正常播放了不崩溃了,但是效率确实不高!
而且视频的质量也下降很多,我想主要是绕了一个大弯:CMSampleBufferRef -> UIImage -> CCTexture2D
如果能够直接:CMSampleBufferRef -> CCTexture2D 效率和视频质量应该能更好,但也只是我的猜测。请高手解答,非常感谢!