Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios OpenGL导致内存泄漏_Ios_Xcode_Memory Leaks - Fatal编程技术网

Ios OpenGL导致内存泄漏

Ios OpenGL导致内存泄漏,ios,xcode,memory-leaks,Ios,Xcode,Memory Leaks,我有一个OpenGL ES活动,出于某种原因,它会导致内存泄漏,甚至在评论了几乎每一行之后。这是剩下的代码 .h文件 #import <UIKit/UIKit.h> #import <GLKit/GLKit.h> @interface PlayMain : GLKViewController <UIAccelerometerDelegate>{ } @end 大约10-20次在openGL活动和另一个活动之间切换后,它包含3个标签和一个按钮,创建返回op

我有一个OpenGL ES活动,出于某种原因,它会导致内存泄漏,甚至在评论了几乎每一行之后。这是剩下的代码

.h文件

#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>

@interface PlayMain : GLKViewController <UIAccelerometerDelegate>{ }

@end
大约10-20次在openGL活动和另一个活动之间切换后,它包含3个标签和一个按钮,创建返回openGL活动的序列,应用程序将收到内存警告。如果我继续,那么在再进行几次切换后,进程将终止。我错过什么了吗


另外,我正在测试的设备是ipod4,我正在项目设置中使用ARC。

您是否运行内存泄漏工具?另外请注意,内存警告可能来自当前在您设备上运行的其他应用程序,因此请尝试关闭它们。我在启用泄漏工具的情况下运行,未发现任何泄漏。测试时,我关闭了所有其他打开的应用程序,因此我非常确定我的应用程序导致内存泄漏。在opengl和其他活动之间切换时,是否再次调用viewDidLoad?i、 e.活动恢复后,您是否查看是否取消分配和分配了活动?是,在活动之间切换时,viewDidLoad每次都被调用。现在我知道您使用ARC,但是opengl上下文的初始化非常麻烦,因为每次加载视图时都会发生这种情况,如果您在活动之间快速切换,我认为在清理旧的活动之前,会多次创建它。
@interface PlayMain ()
{

}

@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKBaseEffect *effect;

@end

@implementation PlayMain{}

@synthesize context = _context;
@synthesize effect = _effect;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
    if (!self.context)
    {
        NSLog(@"Failed to create ES context");
    }

    GLKView *view = (GLKView *)self.view;
    view.context = self.context;
    view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
    [EAGLContext setCurrentContext:self.context];
}

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
}