Objective c Cocos2D项目中神秘的内存泄漏

Objective c Cocos2D项目中神秘的内存泄漏,objective-c,memory-management,memory-leaks,cocos2d-iphone,Objective C,Memory Management,Memory Leaks,Cocos2d Iphone,调用以下代码时,我正在泄漏内存。我尝试了显而易见的方法(在处理完对象后释放该对象,并返回一个自动释放的对象),但出现以下错误: [CCTouchJoint release]:发送到解除分配实例0x1dd10f30的消息 在主回路中: 在CCTouchJoint.h中 以毫米为单位 在级别上退出或重新启动 在init方法中,使用setter(self.touch=…),这是不应该做的。 分配给iVar并直接保留 当您返回自动释放的对象或向另一个方法添加释放时,崩溃(异常消息)是什么 编辑 好的,我

调用以下代码时,我正在泄漏内存。我尝试了显而易见的方法(在处理完对象后释放该对象,并返回一个自动释放的对象),但出现以下错误:

[CCTouchJoint release]:发送到解除分配实例0x1dd10f30的消息

在主回路中:

在CCTouchJoint.h中

以毫米为单位

在级别上退出或重新启动


在init方法中,使用setter(self.touch=…),这是不应该做的。 分配给iVar并直接保留

当您返回自动释放的对象或向另一个方法添加释放时,崩溃(异常消息)是什么

编辑

好的,我不能用你给出的代码重现你的错误。所以它一定在课堂上的其他地方。错误消息是什么

编辑2

如果,而不是

CCTouchJoint *tj = [CCTouchJoint touch:touch withMouseJoint:mouseJoint];
[touchJointList addObject:tj];

[touchJointsHaveNotMoved addObject:tj];
//*If I add [tj release] here we crash
是吗

CCTouchJoint *tj = [CCTouchJoint alloc] initLocal: touch withMouseJoint:mouseJoint];
[touchJointList addObject:tj];

[touchJointsHaveNotMoved addObject:tj];
[tj release]; //does it crash here?? What message?

你好,马里奥,谢谢你的回答。我添加了错误消息,它仅在我自动释放或释放返回的touchjoint时显示。我的问题不在于错误,而在于漏洞;每次我触摸一个对象时,我都会泄漏CCTouchJoints。嗯,它泄漏是因为你注释了释放/自动释放。问题是,为什么你不能返回一个自动释放的对象(使用你给出的相同代码,我这样做没有问题)编辑2:生成与自动释放方法相同的错误消息。奇怪。那么您的可变数组可能有问题…?请注意,我们刚刚假设它们是NSMutableArray。我们没有用于检查该假设的声明或分配。注意:您没有“泄漏”内存,您引用的是一个已发布的对象——几乎完全相反。请注意,
[CCTouchJoint touch:TouchWithMouseJoint:mouseJoint]
应该以“new”开头如果返回保留对象,则使用其他特殊前缀。是否尝试运行Analyzer?是否尝试删除这两个属性并在此类中独占使用IVAR?这两个符号有点多余,可能会导致方法中使用的uz(下划线)符号出现问题。无论如何,您似乎都不是从类外部访问属性。
- (void)dealloc
{
    [touch release];
    [super dealloc];
}

- (id)initLocal:(UITouch *)_touch withMouseJoint:(b2MouseJoint *)_mouseJoint
{
    if ((self = [super init]))
    {
        self.touch = _touch;
        mouseJoint = _mouseJoint;
    }
    return self;
}

+ (id)touch:(UITouch *)_touch withMouseJoint:(b2MouseJoint *)_mouseJoint
{
    return [[self alloc] initLocal:_touch withMouseJoint:_mouseJoint];
   //*If I return an autoreleased object here we crash
}

- (void)destroyTouchJoint
{
    if (mouseJoint != NULL)
    {
        mouseJoint->GetBodyA()->GetWorld()->DestroyJoint(mouseJoint);
    }
}
-(void)removeAllTouchjoints:(BOOL)release{
    //remove touchjoints
    for (CCTouchJoint *tj in touchJointList)
    {
        [tj destroyTouchJoint];
    }

    for (CCTouchJoint *tj in touchJointsHaveNotMoved)
    {
        [tj destroyTouchJoint];
    }

    [touchJointList             removeAllObjects];
    [touchJointsHaveNotMoved    removeAllObjects];

}
CCTouchJoint *tj = [CCTouchJoint touch:touch withMouseJoint:mouseJoint];
[touchJointList addObject:tj];

[touchJointsHaveNotMoved addObject:tj];
//*If I add [tj release] here we crash
CCTouchJoint *tj = [CCTouchJoint alloc] initLocal: touch withMouseJoint:mouseJoint];
[touchJointList addObject:tj];

[touchJointsHaveNotMoved addObject:tj];
[tj release]; //does it crash here?? What message?