How to not to make views stack on views? "Running out of memory"
Ok heres my problem: I have many views in my app, and when im moving from view to view those views are using all of my memory... How can change it to when I move to new and old views it release the previous views?
-(IBAction) bacKToView {
//Switch View Back Home
[self dismissModalViewControllerAnimated:YES];
I've been using this way to change views for a while, but since my app contains many many views there stacking on top of each other and eating all my memory away
I kinda doubt you are showing enough views for that to be too much of an issue in and of itself. Depends on what is in each view, I suppose.
There are things that will happen automatically when memory runs low, and there are things you should do when the view is not currently being shown. You can dump resources in viewDidDisappear and reload them in viewWillAppear, for example.
I kinda doubt you are showing enough views for that to be too much of an issue in and of itself. Depends on what is in each view, I suppose.
There are things that will happen automatically when memory runs low, and there are things you should do when the view is not currently being shown. You can dump resources in viewDidDisappear and reload them in viewWillAppear, for example.
And this assumes you aren't leaking anything.
Ya, well I just started to us Instruments and I have no leaks! But when im looking under "All Allocations" my Overall Bytes keep growing every time im moving from view to view. I read not to go over like 15, I don't know if this is true or if im even reading this correctly... This is my first day working with Instruments...
Well, identify the reason for your crashes before exploring too many possible explanations. For example, if it happens in the simulator, it almost certainly is not a memory issue.
I'm partial to navigation controllers, personally.
Well, identify the reason for your crashes before exploring too many possible explanations. For example, if it happens in the simulator, it almost certainly is not a memory issue.
I'm partial to navigation controllers, personally.
Okay soo I found out the problem... It is the views stacking on top of views, because the app is constantly switching views making the app crash a certain point. So how can I forget the previous views so I can free up memory as I navigate through the app.
Last edited by AdamSubach; 07-29-2010 at 06:25 PM.
And how many views are we talking about? What kind of information is on each view?
I found this about out by running my app through Instruments and every time my apps gets around 11-12 mb the app crashes...
Well right now there is only 10 views but soon to be 50, and they all move in a arithmetic sequence but they sequence can restart back to view 1 and continue. ohh and there are just UIButtons and a pictures on each view connected to audio...
-(IBAction) bacKToView {
//Switch View Back Home
[self dismissModalViewControllerAnimated:YES];
I've been using this way to change views for a while, but since my app contains many many views there stacking on top of each other and eating all my memory away
I'm not sure about the memory aspects of this but it does seem like a edge usage of ModalViewControllers. How about something like
Where THESUPERVIEW is a view containing all the other views - potentially the Window?
OLDVIEW is the view you are leaving
NEWVIEW is the view you are going to
You could create a double linked list representing your view list and then a reusable ViewController that navigates this double linked list.
You could also use a Navigation View Controller and hide the Navigation Bar if you don't want this UI element.
Okay so im looking at my code and it seems like its not the Views! But its the way im mapping out my project... What I'm doing is, is creating a bunch UIViewControler with subclass's with XIB's. I have about 10 of them right now and in ever class .h and .m I have the same exact code which I think is very inefficient. "I think" Soo from that I'm thinking that the same codes keeps on deploying.
Ok, it is clear that you do not have enough experience to arrive at the conclusions you are coming up with. So, stop thinking that you know what the issue is, and start coming up with some hard facts.
I asked if you were receiving memory warnings. You did not answer.
When you crash, what message(s) do you receive?
Answer these questions and you'll be closer to a real solution.
Ok, it is clear that you do not have enough experience to arrive at the conclusions you are coming up with. So, stop thinking that you know what the issue is, and start coming up with some hard facts.
I asked if you were receiving memory warnings. You did not answer.
When you crash, what message(s) do you receive?
Answer these questions and you'll be closer to a real solution.
Memory=No message
And here is the crash log "I dont know if this is what you ment"
That is a crash log, but what I meant was the Console. This is also where you would receive any memory warnings. If you are not receiving memory warnings, then your issue is not related to using too much memory. When testing on a device, I mean. You most likely won't see it when testing in the simulator. So if you still observe the the crash in the simulator, the problem is almost certainly not due to using too much memory.
So, check the Console. If you run out of memory, you will be told there. If you crash, most of the time you will get a line or two providing some information about the crash.
How about the way you call it? The call stack mentions [Stage_1 stage_2] which would be a different spelling. Post the code that you use to go to Stage_2.
How about the way you call it? The call stack mentions [Stage_1 stage_2] which would be a different spelling. Post the code that you use to go to Stage_2.
I checked it and im not seeing anything incorrect but take a look:
The data formatters message could indicate a memory issue. Add log messages to the didReceiveMemoryWarning methods and find out if those are triggering.
Really there are too many possibilities to give you much help without more code.
The data formatters message could indicate a memory issue. Add log messages to the didReceiveMemoryWarning methods and find out if those are triggering.
Really there are too many possibilities to give you much help without more code.
Code:
#import "Stage_2.h"
#import "Stage_3.h"
#import "IPHONEAPP.h"
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
@implementation Stage_2
@synthesize audioPlayer, audioPlayer2;
//Stage_3 Parts- View/Alert/Auido
//
//
-(IBAction) stage_3 {
//View Switch
Stage_3 *screen = [[Stage_3 alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
//Audio-Make sure the audio is at the start of the stream.
self.audioPlayer.currentTime = 0;
[self.audioPlayer play];
}
//backHome Parts- View/Alert/Vibrate/Audio
//
//
-(IBAction)backHome {
//View Switch
IPHONEAPPViewController *screen = [[IPHONEAPPViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
//Alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Woops..."
delegate:self cancelButtonTitle:@"Try Again?" otherButtonTitles:nil];
[alert show];
[alert release];
//Vibrate
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//Audio-Make sure the audio is at the start of the stream.
self.audioPlayer2.currentTime = 0;
[self.audioPlayer2 play];
}
//viewDidLoad Parts
//
//
- (void) viewDidLoad {
//Sound "Foward"
//
//
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fowardSound"ofType:@"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
self.audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:fileURL error:nil];
[self.audioPlayer prepareToPlay];
[filePath release];
[fileURL release];
//Sound "Back"
//
//
NSString *filePath2 = [[NSBundle mainBundle] pathForResource:@"backSound"ofType:@"mp3"];
NSURL *fileURL2 = [[NSURL alloc] initFileURLWithPath:filePath2];
self.audioPlayer2 = [[AVAudioPlayer alloc]
initWithContentsOfURL:fileURL2 error:nil];
[self.audioPlayer2 prepareToPlay];
[filePath2 release];
[fileURL2 release];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[audioPlayer release];
[audioPlayer2 release];
[super dealloc];
}
@end