in Education by
in my project i created a class viewTransistion #import "viewTransition.h" #import "quiz.h" #import "mode.h" #import "result.h" #import "aboutGame.h" #import "ViewController.h" static UIView *cview=nil; static quiz *quizObj=nil; static mode *modeObj=nil; static result *resultObj=nil; static aboutGame *aboutGameObj=nil; static ViewController *viewControllerObj=nil; @implementation viewTransition +(void) viewsTransitionCurrentView:(id)currentView toNextView:(NSString*)nextViewName { if(nextViewName == @"quiz") { quizObj = [[quiz alloc]init]; cview = quizObj.view; NSLog(@"quizObj=%d", [quizObj retainCount]); } if(nextViewName == @"mode") { modeObj = [[mode alloc]init]; cview = modeObj.view; NSLog(@"modeObj=%d", [modeObj retainCount]); } if(nextViewName == @"result") { resultObj = [[result alloc]init]; cview = resultObj.view; NSLog(@"resultObj=%d", [resultObj retainCount]); } if(nextViewName == @"aboutGame") { NSLog(@"aboutGameObj=%d",[aboutGameObj retainCount]); aboutGameObj = [[aboutGame alloc]init]; cview = aboutGameObj.view; } if(nextViewName == @"viewController") { viewControllerObj = [[ViewController alloc]init]; cview = viewControllerObj.view; } [UIView transitionFromView:[currentView view] toView:cview duration:2 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {}]; [currentView release]; cview = nil; } @end its purpose is to perform view transition so i don't have to write code again n again first i created method and variables of this class as non static... i checked on device i was getting leaks maybe because i am alloc initing and not releasing objs in if statements if i release objs in the last i can't perform view transition because on the next view i want to go to is destroyed ...................................... to check i converted this class methods and variables to static so i can check retain counts the reason why i converted to static...if every time new instance is created of this class i will always get retain count 1 of current instance now for the first time i execute this it works fine but if you look at aboutGame if block the first execution prints 0 next time if i want to go again on this page the NSLog line becomes zombie??? ...................................... in the last line [currentView release] is to remove root view controller ... but i didn't alloc init this i am not the owner so why i should release it.. i saw code in a book to release view controller. ...................................... which is the best way to implement this kind of situation static or non-static i am using this class method and variable as static and its working fine no leaks no zombies no problem????? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Some observations: class names should start with a capital letter retainCount is useless. Don't call it. if you are re-assigning an instance variable (or global), you should release the old value before assignment (this may be the source of your memory leak). you are correct; you shouldn't be releasing currentView in that method. which is the best way to implement this kind of situation static or non-static This question doesn't really make sense; it belies a misunderstanding of how view controllers and memory management work on iOS. If you can, I would recommend you convert the project to use ARC (automatic reference counting). That'll mostly take care of the memory management for you (mostly -- you still have to think about it, just not so mechanically). Next, you'll want to dive back into the "programming with ..." guides related to UIView and UIViewController.

Related questions

0 votes
    It is very important to block unknown, strange and ______________ within the corporate network. (a) infected sites (b) ... questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 3, 2021 in Education by JackTerrance
0 votes
    I am newbie to android development and learning it to my own. I have a very strange problem of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I am newbie to android development and learning it to my own. I have a very strange problem of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I'm trying to add copyright to an image. If the resolution of image is less than 4592x2576, it ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    I'm trying to add copyright to an image. If the resolution of image is less than 4592x2576, it ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    2. Why did Tommy & Margie find the printed book strange? Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    Strange binary file generated from machines is an example of tidy data. (a) True (b) False I have ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 29, 2021 in Education by JackTerrance
0 votes
    In JavaScript, object is a container of properties and functions. Properties are identified by ____ and behavior is ... , functions 3. attributes, variables 4. functions, variables...
asked Feb 24, 2021 in Technology by JackTerrance
+1 vote
    In JavaScript, object is a container of properties and functions. Properties are identified by ____ and behavior is ... , functions 3) attributes, variables 4) functions, variables...
asked Oct 9, 2020 in Technology by JackTerrance
0 votes
    I have a major problem which I can't solve. I'm editing question in order to simplify what really ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    I want to create a function which will check if it is a correct hour to make an action, but I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I've been struggling with some issues relating to referencing child controls within a FormView. Another developer ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    We have a requirement for a dexterity content type to have exclude from navigation behaviour but for the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    _______ allows you to modify the error behavior so that you can browse the function call stack (a) debug() ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
...