开发者

Problem in analyzing Leak instrument in ipad

开发者 https://www.devze.com 2023-03-18 12:17 出处:网络
I am using the leak instrument first time. i am getting two leaks in my code, when i saw the source code then it shows at these two bold statements....

I am using the leak instrument first time. i am getting two leaks in my code, when i saw the source code then it shows at these two bold statements....

- (id) initWithFrame: (CGRect) frame
{
    [self LoadMoviePlayer];

    **self= [super initWithFrame:frame];**  
    if (self==[super initWithFrame:frame])
    {
        CAEAGLLayer*开发者_如何学运维 eaglLayer = (CAEAGLLayer*) self.layer;
        eaglLayer.opaque = YES;

- (void) applicationDidFinishLaunching: (UIApplication*) application
{
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    m_window = [[UIWindow alloc] initWithFrame: screenBounds];
    **m_view = [[GLView alloc] initWithFrame: screenBounds];**

    [m_window addSubview: m_view];
    [m_window makeKeyAndVisible];
}

don't know what to do next to solve the problems.


From all I can see, the first leak happens when you execute code in an init without being initialized (your [super initWithFrame:] happens after your [self loadMoviePlayer]), the second, on first sight, seems to be m_view being allocated, but not released, you might solve it using:

CGRect screenBounds = [[UIScreen mainScreen] bounds];

m_window = [[UIWindow alloc] initWithFrame: screenBounds];
m_view = [[GLView alloc] initWithFrame: screenBounds];

[m_window addSubview: m_view];
[m_view release];
[m_window makeKeyAndVisible];

This should work, since the m_view has already being added to the window (and therefore retained).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号