dismissing GLKViewController does not free memory - ios

I got a question to ask. Currently, dismissing GLKViewController is not deallocating the memory at all. Rather, it takes more memory whenever I move to the GLKViewController and dismiss it. My game starts at 100MB. Whenever I play a game, it adds up about 10MB. So, if I play it 10 times, it will be about 200MB in the end. It will crash eventually.
This is my only reference to the GLKViewController. I do not call it anywhere in my uiviewcontroller anywhere other than that. I use modal segue to move to glkviewcontroller.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
Game *renderer = [segue destinationViewController];
[renderer setDelegate:self];
renderer.bomb = bomb;
}
And I dismiss it using [self dismissViewControllerAnimated:YES completion:nil]
Do you know how to fix this problem? It is wasting so much time right now. Thanks.

Related

Passing data back from Segue

It has been some months that I've programmed for iOS, and want to finish my game with new features. Now when people play the game and lose they will see a "Game Over" view.
Now what I want is that people first see a view where they can use the bought credits they gotten and go back to the game with the extra seconds or life. But I'm not doing it on the right way.
Way I'm trying to do:
- Save Me View (Segue)
Game view -
- Game Over View (Segue)
So, you lose, go automatically to the save me view, presses close and go to game over immediately. Otherwise use the NSUserDefaults that has been saved before showing the Save Me view.
So I'm using NSUserDefaults for saving previous game levels/points etc and that is not the right way of doing and the flow is getting complicated.
Second try:
I've tried it but I'm stuck at the last step. Because I'm using Segue's and delegates, I don't know how to make my GameView the delegate of the SaveView, while the protocols are already there.. I've followed this: Passing Data between View Controllers
Now at step 6 it doesn't work because i'm using modal segue's with my UIViewControllers and no UINavigationControllers. I've this in my code atm:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"SaveMe"]){
SaveMeViewController *vc = [segue destinationViewController];
// Here needs to come that GameView (This Class) is the delegate for SaveMeViewController. Tried vc.delegate = self; but this doesn't work.
[self savePoints];
}
}
You could setup a delegate in the gave view that passes back how the game ended.
As my understanding use #property or delegate to pass data it will help you.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"SaveMe"]) {
SaveMeViewController * vc = segue.destinationViewController;
// create property in SaveMeViewController and access that property and pass values
vc.property = value to assgin;
}
}

Carry on playing AVPlayer stream when view controller is popped

I have a NavigationViewController which is holding a a table of Streams that could be played. When user selects one of the streams it push's the 'RadioDetailViewController' and start streaming from URL.
What I want is when I navigate back to the rootViewController(NavigationViewController) I want the AVPlayer to carry on streaming.
Anyone able to help?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *navController = [segue destinationViewController];
RadioTableViewController *radioTableViewController = (RadioTableViewController *)([navController viewControllers][0]);
[radioTableViewController setRadioStreamContinue:radioStream];
}
Then in my rootViewController I do this:
- (void)viewDidLoad{
[radioStreamContinue play];
[super viewDidLoad];
}
This doesn't do anything and the stream stops. Sorry I'm new this and would appreciate any help.
I stumbled on this trying to look for a cleaner solution... but have you tried setting the audio player property in the app delegate and setting it with resources from the view controller? This way the player object isn't released when the view controller is deallocated.
(I wouldn't really consider this a great answer but I don't have the rep to comment yet)

Memory Leak with MapView ios7

I have 2 viewControllers: The first one is the mainViewController that sends after pressing a button to the second viewController with a Push method, the second viewController has a mapView that shows my position. The problem is that the first time I start the app the memory used by the mainViewController is near 15mb but after switching to the second viewController and pressing the back button in order to go back to mainViewController the memory used it's near 40mb, I'm using storyboards and arc does anyone have a solution for this?
Try this in your viewWillDisappear:(BOOL)animated method in your second view controller, the one with the map:
mapView.showsUserLocation = NO;
mapView.delegate = nil;
[mapView removeFromSuperview];
mapView = nil;

Modally presented UIViewController does not empty memory on close

I have a problem, that caused me quite some hours/days of debugging so far.
My situation is:
i have a viewcontroller that displays some data
when a user clicks a button another view controller is presented modally
after the user closes the modal controller, the memory usage does not decrease
I do not hold references (either weak or strong) for the modal view anywhere.
This is how the segue is performed:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *nav = [segue destinationViewController];
SomeViewController *vc = (SomeViewController *)[nav topViewController];
vc.dataArray = self.dataArray; // dataArray is a weak reference
}
And this is how i close it:
-(void)closeButtonClickHandler:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
In my viewDidDisapear method, i set everything to nil
- (void)viewDidDisappear:(BOOL)animated
{
[self.map removeAnnotations:self.myMap.annotations];
self.map.delegate = nil;
self.map = nil;
self.view = nil;
[super viewDidDisappear:animated];
}
But the controller still remains in memory. What is even worse is, that if i open it multiple times, it keeps adding to the consumed memory until eventually the OS is forced to close the application.
Any/all help is appreciated :)
I of found out that a small side view had a wrong reference set. It was 'strong', should have been 'weak'
#property (nonatomic, weak) UISomeView * someView;
After that the memory was released normally and did not stack up any more
tnx #JonathanCicohons for the hint :)

Memory not being released after deleting vc with UIWebView but no leak detected by analysis tools

I've got a simple app which is just loading a view controller which contains a UIWebView. While running it I noticed that the amount of memory reported by XCode increases from 2 MB before the vc is allocated up to 12.5Mb after its been created.
But then after the vc is deleted the amount of memory doesn't go down, in fact it rises even further to 13Mb. However XCode's leaks analyser doesn't report any problems.
The view controller is created and destroyed here from within the app's main (and only other) view controller:
- (void) viewDidAppear:(BOOL)animated
{
static BOOL presented = NO;
if (!presented)
{
PresentationViewController *vc = [[PresentationViewController alloc] initWithPresentationId:#"index.html"];
__weak typeof(vc) weakVc = vc;
[vc setExitBlock:^{
[[weakVc presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}];
[self presentViewController:vc animated:YES completion:nil];
presented = YES;
}
}
And the view controller's dealloc is called so it is being destroyed, and yes the web view delegate is being nilled.
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.webView stopLoading];
self.webView.delegate = nil;
}
Why isn't the memory consumption going down when the view controller is deleted?
Try repeat the action over 3 times or even more , see if the memory is still keep growing or stay near a fixed value. iOS some times caches the view for further use, even if you removed it.
Check your project Scheme to see if you have set the "Enable Zombie Objects" on, that could leads to crazy memory growth.
try use intrumemnts, set the Allocations Track Display Style to Active Allocation Dstribution, Mark Generation->load the webveiew->quit the webview->Mark Generation->repeat 3 times. By this way you can find what's left in your memory Allocations and which codes caused it.

Resources