次のコードを呼び出すと、メモリ リークが発生します。私は明らかなことを試しました(オブジェクトを使い終わった後にオブジェクトを解放し、自動解放されたオブジェクトを返します)が、次のエラーが発生します:
[CCTouchJoint リリース]: 割り当て解除されたインスタンス 0x1dd10f30 に送信されたメッセージ
メインループ内:
CCTouchJoint *tj = [CCTouchJoint touch:touch withMouseJoint:mouseJoint];
[touchJointList addObject:tj];
[touchJointsHaveNotMoved addObject:tj];
//*If I add [tj release] here we crash
CCTouchJoint.h 内
@interface CCTouchJoint : NSObject
{
@public
    b2MouseJoint *mouseJoint;
    UITouch *touch;
}
@property (assign) b2MouseJoint *mouseJoint;
@property (nonatomic, retain) UITouch *touch;
CCTouchJoint.mm 内
- (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];
}