Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5985423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:31:41+00:00 2026-05-22T22:31:41+00:00

My problem is, that some layers nerver gets deallocated. My previews conviction was, that

  • 0

My problem is, that some layers nerver gets deallocated. My previews conviction was, that [CCDirector sharedDirector] replaceScene:[Menu node]]; or similar does everything for me. There stays active layers in the background, if I load a new layer. That leads to weird bugs. Anyway, the code at the bottom has a retain count of 2 while the onExit call. Dealloc is never called. To remove the rootVC solves the problem. Unfortunately I need it.

#import "Help.h"
#import "Constants.h"
#import "MainMenu.h"


@implementation Help

-(void)showText:(ccTime)dt
{
    [self unschedule:_cmd];
    txt.hidden = NO;
}

-(void)onExit
{
    CCLOG(@"retain count %i", [self retainCount]);
    [super onExit];
}

-(id) init
{
    if ( (self = [super init]) ) 
    {
        NSString* bgPath;
        NSString* button2Path;
        NSString* button2PressPath;
        CGRect textFrame;
        int fontsize;
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            bgPath = @"background-ipad.png";
            button2Path = @"button2-ipad.png";
            button2PressPath = @"button2_press-ipad.png";
            textFrame = CGRectMake(60, 140, 920, 500);
            fontsize = 24;
        } else {
            bgPath = @"background.png";
            button2Path = @"button2.png";
            button2PressPath = @"button2_press.png";
            textFrame = CGRectMake(10, 45, 460, 217);
            fontsize = [kMenuFontSize intValue];
        }

        NSString* helpText = NSLocalizedString(@"Bla bla bla yada yada yada", @"Helptext");



        rootVC = [UIApplication sharedApplication].keyWindow.rootViewController; // +1 retain to the layer
        txt = [[[UITextView alloc] initWithFrame:textFrame] autorelease];
        txt.text = helpText;
        [txt setEditable:NO];
        [txt setFont:[UIFont fontWithName:@"Sui Generis" size:fontsize]];
        [txt setTextColor:[UIColor whiteColor]];
        [txt setBackgroundColor:[UIColor clearColor]];
        [rootVC.view addSubview:txt];
        txt.hidden = YES;
        [self schedule:@selector(showText:) interval:1];

        self.isTouchEnabled = NO;

        CGSize ss = [[CCDirector sharedDirector] winSize];

        CCSprite* background = [CCSprite spriteWithFile:bgPath];
        background.position = ccp(ss.width*0.5, ss.height*0.5);
        [self addChild:background z:0];

        CCLabelTTF* backLabel = [CCLabelTTF labelWithString:NSLocalizedString(@"Back", @"back button at help") fontName:kMenuFont fontSize:fontsize];
        backLabel.position = ccp(ss.width * 0.1, ss.height * 0.1);
        [backLabel setColor:ccBLACK];
        [self addChild:backLabel z:20];
        CCMenuItemImage* backButton = [CCMenuItemImage itemFromNormalImage:button2Path selectedImage:button2PressPath block:^(id sender) {

            [txt removeFromSuperview];
            id trans = [CCTransitionFade transitionWithDuration:1 scene:[MainMenu node]];
            [[CCDirector sharedDirector] replaceScene:trans];
        } ];
        backButton.position = ccp(ss.width * 0.1, ss.height * 0.1);
        CCMenu* menu = [CCMenu menuWithItems:backButton, nil];
        [menu setPosition:ccp(0,0)];
        [self addChild:menu z:10];

    }
    return self;
}

-(void)dealloc
{
    CCLOG(@"Help dealloc");
    [super dealloc];
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:31:41+00:00Added an answer on May 22, 2026 at 10:31 pm

    Do not call retainCount

    It is useless.

    You need to make sure your retains and releases are balanced. Sometimes, this means making sure that you have correctly torn down any dependent state that may be retaining your object.

    For example, this:

        [self schedule:@selector(showText:) interval:1];
    

    If it is using an NSTimer with self as the target, it’ll retain self. Since your onExit is being called, do you need to effectively “unschedule” self? (I haven’t read the cocos2d source to know definitively).


    How do I release rootVC =
    [UIApplication
    sharedApplication].keyWindow.rootViewController;
    // +1 retain to the layer. [self
    release] doesn’t work.

    This question doesn’t make any sense; calling methods that return objects should not increase the retain count and, obviously, releasing self isn’t going to work.

    It isn’t clear what you are asking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, my problem is that some providers support SREG and some support only AX
A problem that has frequently come up in my career is I have some
I'm having the weird problem that after having javascript inject some dom-elements the css-rules
For some reason one installation of Moodle 1.9.3+ has a problem that file.php returns
I am loading some text dynamically into a div, but have the problem that
Problem: We have a web app that calls some web services asynchronously (from the
My problem is that every time I do some operation with an URL like
My problem is that The code in the branch I'm working in for some
I had a performance problem today that showed up after some profiling. Calls to
I've got a sproc and some C# calling it. My problem is that both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.