0

我在我的 Objective-C 应用程序中使用 C++,并在场景中进行以下分配:

@interface Game1PlayerLayer : CCLayer {

    b2World *_world;
    GLESDebugDraw *_debugDraw;
    MyContactListener *_contactListener;
}

+(CCScene *) scene;

@end

在实施中,我分配:

_world = new b2World(gravity);
_debugDraw = new GLESDebugDraw(PTM_RATIO);
_contactListener = new MyContactListener();

当然,我必须用

delete _world;
delete _debugDraw;
delete _contactListener;

但如果我不删除它们,Xcode Leaks 仪器不会显示这些泄漏。我当然检查了是否Game1PlayerLayer发生了释放。泄漏仪器设置为 1 秒快照。如果 Xcode 能够显示 C++ 泄漏,我应该如何跟踪它们?

4

1 回答 1

0

如何避免整个问题并std::shared_ptr改为使用?

@interface Game1PlayerLayer : CCLayer {

    std::shared_ptr<b2World> _world;
    std::shared_ptr<GLESDebugDraw> _debugDraw;
    std::shared_ptr<MyContactListener> _contactListener;
}


_world.reset(new b2World(gravity));
_debugDraw.reset(new GLESDebugDraw(PTM_RATIO));
_contactListener.reset(new MyContactListener());


#if 0
delete _world;
delete _debugDraw;
delete _contactListener;
#endif
于 2013-10-01T10:22:32.663 回答