Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-21-2010, 11:01 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 85
acdesign is on a distinguished road
Default Received memory warning. Level=1

Hey guys,
i have a very basic app that just goes through view controllers with UIImageViews in them with some pics. I have about 30 nibs so far but after cycling through a few my app slows down and i get

Received memory warning. Level=1

now to overcome this do i have to load an image into the image view through the code because up to now i have it loaded in interface builder.
And if so i know how to load it in but i dont know how to keep my buttons above the loaded image. When i call an image it goes to the top? Can anyone help me cheers.
acdesign is offline   Reply With Quote
Old 07-21-2010, 11:09 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 34
ErichGS is on a distinguished road
Default

More likely, you need to make sure the memory taken up by the picture is released when it is no longer displayed.
ErichGS is offline   Reply With Quote
Old 07-21-2010, 11:09 AM   #3 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Hard to say without knowing how your app is structured or what it does. If you have lots of images, you cannot have all of them in memory at the same time. You will have to load/unload as needed.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-21-2010, 11:12 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 85
acdesign is on a distinguished road
Default

Here is some example code


#import "The_Ride_Vol_1ViewController.h"
#import "s0.h"
#import "p1.h"
#import "p2.h"

@implementation p1
@synthesize landscapeViewController, imageScrollView;

- (void)dealloc
{
//[[NSNotificationCenter defaultCenter] removeObserver:self];
// [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[landscapeViewController release];
[imageScrollView release];
[super dealloc];
}

- (void)willAnimateRotationToInterfaceOrientationU IInterfaceOrientation)interfaceOrientation durationNSTimeInterval)duration{

if(self.interfaceOrientation == UIDeviceOrientationPortrait || self.interfaceOrientation == UIDeviceOrientationLandscapeRight){

s0 *viewController = [[s0 alloc] init];
self.landscapeViewController = viewController;
[viewController release];
[self presentModalViewController:landscapeViewController animated:YES];


//setup your interface for portrait

} else if(self.interfaceOrientation == UIDeviceOrientationLandscapeLeft || self.interfaceOrientation == UIDeviceOrientationPortrait){

[landscapeViewController dismissModalViewControllerAnimated:YES];

//setup your interface for landscape

}
}

- (IBAction)goToSecondController{
p2 *controller = [[p2 alloc] initWithNibName:@"p2" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
}

- (IBAction)goToFirstController{
The_Ride_Vol_1ViewController *controller = [[The_Ride_Vol_1ViewController alloc] initWithNibName:@"The_Ride_Vol_1ViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
}

- (BOOL)shouldAutorotateToInterfaceOrientationUIIn terfaceOrientation)interfaceOrientation
{
return YES; // support only portrait
}

@end
acdesign is offline   Reply With Quote
Old 07-21-2010, 11:23 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 85
acdesign is on a distinguished road
Default

should i be using this instead to release the image?


CGRect myImageRect = CGRectMake(0.0f, 0.0f, 768.0f, 1024.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"p1.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
acdesign is offline   Reply With Quote
Old 07-21-2010, 11:23 AM   #6 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 34
ErichGS is on a distinguished road
Default

You are continually stacking views as modal, which I believe means the resources of any of them will never be released. Even if you go back to the first image, you present it as a modal view controller. Is there a reason to have each image in it's own view controller? If not why not have a single image view and just change it's image as you need to?

Edit:

Quote:
Originally Posted by acdesign View Post
should i be using this instead to release the image?


CGRect myImageRect = CGRectMake(0.0f, 0.0f, 768.0f, 1024.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"p1.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
Yes, that and then just change the image of the image view every time the buttons are pushed.
ErichGS is offline   Reply With Quote
Old 07-21-2010, 12:18 PM   #7 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 85
acdesign is on a distinguished road
Default

Well the reason i have them in a view each is that when one page is turned it goes to a spread in a landscape nib. Is there any way around this?
acdesign is offline   Reply With Quote
Old 07-21-2010, 12:24 PM   #8 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 85
acdesign is on a distinguished road
Default

Quote:
Originally Posted by ErichGS View Post
You are continually stacking views as modal, which I believe means the resources of any of them will never be released. Even if you go back to the first image, you present it as a modal view controller. Is there a reason to have each image in it's own view controller? If not why not have a single image view and just change it's image as you need to?

Edit:



Yes, that and then just change the image of the image view every time the buttons are pushed.

would this code work if i put this in each view controller

- (void)viewDidUnload {
[self dismissModalViewControllerAnimated:YES];
}
acdesign is offline   Reply With Quote
Old 07-21-2010, 12:28 PM   #9 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 34
ErichGS is on a distinguished road
Default

You would probably have to organize your code so each modal view controller is a direct child of your first view controller. I am not sure what is going to happen when you dismiss a modal view controller on which you have presented another modal view controller, but I can't imagine it will be anything good.
ErichGS is offline   Reply With Quote
Old 07-21-2010, 12:30 PM   #10 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 85
acdesign is on a distinguished road
Default

Quote:
Originally Posted by ErichGS View Post
You would probably have to organize your code so each modal view controller is a direct child of your first view controller. I am not sure what is going to happen when you dismiss a modal view controller on which you have presented another modal view controller, but I can't imagine it will be anything good.
How would i make it a direct child of the other view? cheers
acdesign is offline   Reply With Quote
Old 07-21-2010, 12:36 PM   #11 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 34
ErichGS is on a distinguished road
Default

Quote:
Originally Posted by acdesign View Post
How would i make it a direct child of the other view? cheers
Your button clicks call a method in your first view controller. That method takes an argument to determine which view controller to launch. The code in that method dismisses the current modal view controller and then launches the new modal view controller based on the passed argument.
ErichGS is offline   Reply With Quote
Old 07-21-2010, 01:04 PM   #12 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 85
acdesign is on a distinguished road
Default

Quote:
Originally Posted by ErichGS View Post
Your button clicks call a method in your first view controller. That method takes an argument to determine which view controller to launch. The code in that method dismisses the current modal view controller and then launches the new modal view controller based on the passed argument.

can anybody give me an example of what this would look like please i know this is a newb question but it would help a hell of a lot
acdesign is offline   Reply With Quote
Old 07-21-2010, 01:22 PM   #13 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 85
acdesign is on a distinguished road
Default

do you guys think this is the way around it

if(avController == nil)
avController = [[AddViewController alloc] initWithNibName:@"AddView" bundle:nil];

if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];

[self.navigationController presentModalViewController:addNavigationController animated:YES];
acdesign is offline   Reply With Quote
Old 07-21-2010, 01:47 PM   #14 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 34
ErichGS is on a distinguished road
Default

In your first view controller:

Code:
-(void) modalViewSelectorMethod:(int) viewIndex
{
   if ([self modalViewController])
      [self dismissModalViewControllerAnimated:YES];

   switch(viewIndex) {
        case 0:
        {
               // do nothing to keep the root view controller displayed
               break;
        }    
        case 1:
        {
               p1 *controller = [[p1 alloc] initWithNibName:@"p1" bundle:nil];
               controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
               [self presentModalViewController:controller animated:YES];
               [controller release];
               break;
        }
        case 2:
        {
               p2 *controller = [[p2 alloc] initWithNibName:@"p2" bundle:nil];
               controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
               [self presentModalViewController:controller animated:YES];
               [controller release];
               break;
        }
        // continue for all your view controllerscase ...
        default:
        {
               // if an invalid index is supplied just return to the initial view controller
               break;
         }
    }
        
}

Then from your other view controllers

Code:
- (IBAction)goToSecondController{
[[self parentViewController] modalViewSelectorMethod:2];
}

- (IBAction)goToFirstController{
[[self parentViewController] modalViewSelectorMethod:0];
}
Of course it would still be much better to come up with a view controller that is generic enough to handle what ever you want to do with the image and then just change the image with in that view controller.
ErichGS is offline   Reply With Quote
Old 09-14-2010, 07:19 AM   #15 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 1
j_talevska is on a distinguished road
Default Release everything at once

Hi, I'm wondering if there's a way to release everything from memory at once, just like if the app is being restarted and the memory is cleared? Any help appreciated.
Thanks.
j_talevska is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 332
15 members and 317 guests
akphyo, alexP, appservice, bignoggins, EXOPTENDAELAX, flamingliquid, guusleijsten, Hamad, mariano_donati, Objective Zero, ohmniac, Paul Slocum, Rudy, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:42 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0