ios - ViewController allocation and deallocation problems -


i have 2 "loops" in app between viewcontroller.

first loop game-loop. @ first vc level displayed. second vc game screen , if game finished, third vc appear bonus point, stars, , on.

the second "loop" 3 vc swiping.

enter image description here

ok, problem? have problems deallocations. example, overtime swipe, locations going in sínstruments, curve getting higher , higher...

also game loop. can't deallocate vc before.

i think didn't understand correctly how [self dismissviewcontrolleranimated:no completion:nil]; works.

is right, method sent parent vc, , parent vc deallocate vc execute method?

is parent vc initial vc?

how can dismiss , deallocate view controllers correctly in "loops"?

now, allocing curve in instruments getting higher , higher @ each level, , level 18-21 app crashing, think because of allocations.

can tell me hoe can solve problems?

to begin questions:

  • is right method sent parent vc, , parent vc deallocate vc execute method?

from documentation dismissviewcontrolleranimated:completion:

the presenting view controller responsible dismissing view controller presented. if call method on presented view controller itself, uikit asks presenting view controller handle dismissal.

  • is parent vc initial vc?

parenting bit complex structure. normally, when vc (let's call x) presents vc (this 1 y), x parent of y. must share additional code such how you're allocating these vc's, how/when you're presenting them, etc. know 1 "most" parent.

when call [self presentviewcontroller:y animated:** completion:** on x;

x presentingviewcontroller.

y presentedviewcontroller.

hence, x responsible 1 y. parent :) so, question bit invalid scheme. however, can initial vc parent of vc's that's presented him. (for example, if embed navigation controller vc's, root vc , responsible "winding/unwinding", makes "parent".)

normally, view controllers should not go in loop between themselves. can dependable on each other, shouldn't create loops.

solution proposal:

it seems me you're duplicating these 3 kind of vc's every time level begins. that's first loop's problem. second loop bit complex, assume want save state of vc's while swiping other vc's.

1. manipulating current vcs.

these vcs must have option clear state, should reset loaded first time. create these vcs once, , reset them if needed.

2. create singleton class hold these vcs.

(caution: since solution involves holding vcs in class, hold memory. won't drawn window, though.)

when start app, singleton created, , create vcs needed @ same time. class should have methods like:

addviewcontrollertostack: showviewcontroller:animated:completion: resetviewcontroller: 

and of course properties hold these vcs.

3. control through singleton

when user presses button "go x level", must interact singleton class you've created. if you're going dismiss vc, singleton should that. presentation.

summary:

with method, cannot create multiple vcs of same type. can use 1 created singleton class, , can reuse them. cautious, since you're not deallocating vc, may end residues (like forgetting reset/remove timers, reset score, etc).

i've used in 1 of project, required view controller opengl. couldn't dismiss since it's doing calculations. , could've been created once. bad part is, in middle of vc segues. so, whenever needed present vc, call singleton class show me. , create once.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -