我的内心内存问题开始方法 [英] memory issue inside my touchesBegan methodh

查看:37
本文介绍了我的内心内存问题开始方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中存在内存问题.但是我不知道如何解决.这就是我在做什么.就像您在下面看到的那样,我有一张地图,上面有城市.当您点击一个城市时,城市会亮起.

I have a memory issue inside my project. But I don't know how to solve it. This is what I'm doing. Like you can see below I have a map with cities on it. When you tap on a city, the city lights up.

这就是我在touchesBegan方法中所做的.

This is what I do in my touchesBegan method.

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        NSLog(@"Touched");
        CGPoint c = [[touches anyObject] locationInView: self];
        struct CGPath *pat = (__bridge struct CGPath *)([arrayPaths objectAtIndex:0]);
        struct CGPath *pat2 = (__bridge struct CGPath *)([arrayPaths objectAtIndex:1]);
        // repeat this line 42 time (creating a struct for every city)

       CGPathRef  strokedPath = CGPathCreateCopy(pat);
       CGPathRef  strokedPath2 = CGPathCreateCopy(pat2);
       //I also repeated this line 42 times

       BOOL pointIsNearPath = CGPathContainsPoint(strokedPath, NULL, c, NO);
       BOOL pointIsNearPath2 = CGPathContainsPoint(strokedPath2, NULL, c, NO);
       //I also repeated this line 42 times

       CFRelease(strokedPath);
       CFRelease(strokedPath2);
       //I also repeated this line 42 times



if (pointIsNearPath){
         if([self.subviews containsObject:_imgLommel]) {
             NSLog(@"Remove");
             [_imgLommel removeFromSuperview];
             [arrCities removeObject:[NSNumber numberWithInt:1]];
         }else{
             NSLog(@"add");
           [self addSubview:_imgLommel];
             [arrCities addObject:[NSNumber numberWithInt:1]];
         }
    }
    if (pointIsNearPath2){
        if([self.subviews containsObject:_imgHechtel]) {
            NSLog(@"Remove");
            [_imgHechtel removeFromSuperview];
            [arrCities removeObject:[NSNumber numberWithInt:2]];
        }else{
            NSLog(@"add");
            [self addSubview:_imgHechtel];
            [arrCities addObject:[NSNumber numberWithInt:2]];
        }
    }
     //What I do here is I place an image with the colored city on top off the other images. If the image is already there I remove it.

//I also repeated this line 42 times

现在是问题所在.一切顺利.但是在选择了几张图像之后,该应用程序关闭了,并且没有收到任何错误消息.数周以来,我一直在努力解决这个问题.

So now the problem. Every thing goes good. But after selecting several images, the app shuts down and I get no error messages. I'm struggling with this problem for weeks know.

可以请别人帮我吗?

亲切的问候.

编辑

经过一些测试,我发现在注释掉以下几行时我没有得到错误:

After some testing I found out that I don't get the errors when I comment out the following lines:

if (pointIsNearPath43){
        if([self.subviews containsObject:_imgHoeselt]) {
            NSLog(@"Remove");
          //  [_imgHoeselt removeFromSuperview];
            [arrCities removeObject:[NSNumber numberWithInt:43]];
        }else{
            NSLog(@"add");
          //  [self addSubview:_imgHoeselt];
            [arrCities addObject:[NSNumber numberWithInt:43]];
        }
    }

//Commented it also out in the other cities.

推荐答案

启用NSZombieEnabled来检查项目中的内存问题.

enable NSZombieEnabled to check memory issue inside project.

  1. 转到编辑方案->参数然后

2-选择诊断"标签,然后单击启用僵尸对象"

2- select the "Diagnostics" tab and click "Enable Zombie Objects"

这会将释放的对象转换为NSZombie实例,并在再次使用时打印控制台警告.这是一个调试辅助工具,可以增加内存使用量(没有释放任何对象),但可以改善错误报告.

This turns released objects into NSZombie instances that print console warnings when used again. This is a debugging aid that increases memory use (no object is really released) but improves error reporting.

一种典型情况是,当您过度释放一个对象却不知道是哪个对象时:

A typical case is when you over-release an object and you don't know which one:

这篇关于我的内心内存问题开始方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆