1

I have made an app, but on ipad 1 it crashes in the end part. On ipad-higher it remains working, but still I think I am doing something wrong, I really need to make something working more economically. But what is it?

In the end part it all happens. Before that, several screens are put onto each other and in the simulator when you go back they all are dismissed. But on the ipad 1 you will not even reach the end of the end part. I will try to explain what happens and several idea's about what is happening I have.

You can swipe on the screen and retina images (big images) are exchanged with the four corners that can get selected, each with a different image-background. There are six different scenes, so there are 6x4 + 6x1 for-normal-0-situation, 25 big retina images. There are only 5 frames working on top of each other (4 corners and 1 background), but I set inactive stuff to nil and load active images with imageNamed. It goes well on the simulator, but it crashes on the ipad 1, with no low memory warning or what so ever.

I've studied improvements: a) autorelease pool b) imageNamed replaced by imageContentsOfFile. The autorelease pools don't have any effect. imageNamed, I couldn't get imageContentsOfFile working, so I skipped the operation.

Any ideas of what is so excessively wrong and what kind of thoughts can be applied to have it work more economically, for it somewhere is demanding way too much in the end.

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint tappedPt = [[touches anyObject] locationInView:self.view];

NSArray *subviews = [[NSArray alloc]init];

subviews = [self.view subviews];

// Return if there are no subviews
if ([subviews count] == 0) return;

for (UIView *subview in subviews) {
    if ([subview pointInside:[self.view convertPoint:tappedPt toView:subview]    withEvent:event]){

        [self checkAndChange:subview];

        [self modifyChoice:subview];
    }
}
}


- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// Get the subviews of the view

CGPoint tappedPt = [[touches anyObject] locationInView:self.view];

NSArray *subviews = [[NSArray alloc]init];

subviews = [self.view subviews];

// Return if there are no subviews
if ([subviews count] == 0) return;

for (UIView *subview in subviews) {

    if ([subview pointInside:[self.view convertPoint:tappedPt toView:subview] withEvent:event]){

        [self checkAndChange:subview];

        [self modifyChoice:subview];

    }

}

}

-(void) modifyChoice:(UIView *)subview
{
if(subview==area1LinksBoven){[gekozenExpressieBijDimensie replaceObjectAtIndex:dimensie-1 withObject:[NSNumber numberWithInteger:1]];}
if(subview==area2RechtsBoven){[gekozenExpressieBijDimensie replaceObjectAtIndex:dimensie-1 withObject:[NSNumber numberWithInteger:2]];}
if(subview==area3RechtsOnder){[gekozenExpressieBijDimensie replaceObjectAtIndex:dimensie-1 withObject:[NSNumber numberWithInteger:3]];}
if(subview==area4LinksOnder){[gekozenExpressieBijDimensie replaceObjectAtIndex:dimensie-1 withObject:[NSNumber numberWithInteger:4]];}

if(maxChoice<dimensie){maxChoice=dimensie;
    if(maxChoice==1){headerGevuld.image = [UIImage imageNamed:@"TOP1.png"];}
    if(maxChoice==2){headerGevuld.image = [UIImage imageNamed:@"TOP2.png"];}
    if(maxChoice==3){headerGevuld.image = [UIImage imageNamed:@"TOP3.png"];}
    if(maxChoice==4){headerGevuld.image = [UIImage imageNamed:@"TOP4.png"];}
    if(maxChoice==5){headerGevuld.image = [UIImage imageNamed:@"TOP5.png"];}
    if(maxChoice==6){headerGevuld.image = [UIImage imageNamed:@"TOP6.png"];}
}
}

-(void) checkAndChange:(UIView *)subview{

if(subview==area1LinksBoven){
    area1LinksBoven.image = [UIImage imageNamed:@"SELECTION1.png"];
    area2RechtsBoven.image = nil;
    area3RechtsOnder.image = nil;
    area4LinksOnder.image = nil;
    footer.image = [UIImage imageNamed:@"FOOT1.png"];
    @autoreleasepool {
    if(dimensie==1){
        filmAchtergrond0.image = [UIImage imageNamed:@"1PassiefActiefOntspanning.jpg"];}
    if(dimensie==2){
        filmAchtergrond0.image = [UIImage imageNamed:@"1MakkelijkMoeilijkMaster.jpg"];}
    if(dimensie==3){
        filmAchtergrond0.image = [UIImage imageNamed:@"1VeiligGevaarlijkGeborgenheid.jpg"];}
    if(dimensie==4){filmAchtergrond0.image = [UIImage imageNamed:@"1NormaalBijzonderGeaard.jpg"];}
    if(dimensie==5){filmAchtergrond0.image = [UIImage imageNamed:@"1AlleenSamenUniek.jpg"];}
    if(dimensie==6){filmAchtergrond0.image = [UIImage imageNamed:@"1OrdeChaosDuidelijk.jpg"];}
    }
    [arrowRight setImage:[UIImage imageNamed:@"ARROW_RIGHT_ACTIVE.png"] forState:UIControlStateNormal];
}
if(subview==area2RechtsBoven){
    area1LinksBoven.image = nil;
    area2RechtsBoven.image = [UIImage imageNamed:@"SELECTION2.png"];
    area3RechtsOnder.image = nil;
    area4LinksOnder.image = nil;
    footer.image = [UIImage imageNamed:@"FOOT2.png"];
    @autoreleasepool {        
    if(dimensie==1){filmAchtergrond0.image = [UIImage imageNamed:@"2PassiefActiefEnergiek.jpg"];}
    if(dimensie==2){
        filmAchtergrond0.image = [UIImage imageNamed:@"2MakkelijkMoeilijkUitdagend.jpg"];}
    if(dimensie==3){
        filmAchtergrond0.image = [UIImage imageNamed:@"2VeiligGevaarlijkSpannend.jpg"];}
    if(dimensie==4){filmAchtergrond0.image = [UIImage imageNamed:@"2NormaalBijzonderWow.jpg"];}
    if(dimensie==5){filmAchtergrond0.image = [UIImage imageNamed:@"2AlleenSamenGezellig.jpg"];}
    if(dimensie==6){filmAchtergrond0.image = [UIImage imageNamed:@"2OrdeChaosImproviseren.jpg"];}
    }
    [arrowRight setImage:[UIImage imageNamed:@"ARROW_RIGHT_ACTIVE.png"] forState:UIControlStateNormal];
}
if(subview==area3RechtsOnder){
    area1LinksBoven.image = nil;
    area2RechtsBoven.image = nil;
    area3RechtsOnder.image = [UIImage imageNamed:@"SELECTION3.png"];
    area4LinksOnder.image = nil;
    footer.image = [UIImage imageNamed:@"FOOT3.png"];
    @autoreleasepool {
    if(dimensie==1){
        filmAchtergrond0.image = [UIImage imageNamed:@"3PassiefActiefUitputting.jpg"];}
    if(dimensie==2){
        filmAchtergrond0.image = [UIImage imageNamed:@"3MakkelijkMoeilijkFrustrerend.jpg"];}
    if(dimensie==3){
        filmAchtergrond0.image = [UIImage imageNamed:@"3VeiligGevaarlijkGevaarlijk.jpg"];}
    if(dimensie==4){
        filmAchtergrond0.image = [UIImage imageNamed:@"3NormaalBijzonderOnbegrijjpelijk.jpg"];}
    if(dimensie==5){filmAchtergrond0.image = [UIImage imageNamed:@"3AlleenSamenGroepsdruk.jpg"];}
    if(dimensie==6){filmAchtergrond0.image = [UIImage imageNamed:@"3OrdeChaosRommeltje.jpg"];}
    }
    [arrowRight setImage:[UIImage imageNamed:@"ARROW_RIGHT_ACTIVE.png"] forState:UIControlStateNormal];
}
if(subview==area4LinksOnder){
    area1LinksBoven.image = nil;
    area2RechtsBoven.image = nil;
    area3RechtsOnder.image = nil;
    area4LinksOnder.image = [UIImage imageNamed:@"SELECTION4.png"];
    footer.image = [UIImage imageNamed:@"FOOT4.png"];
    @autoreleasepool {
    if(dimensie==1){filmAchtergrond0.image = [UIImage imageNamed:@"4PassiefActiefApathie.jpg"];}
    if(dimensie==2){filmAchtergrond0.image = [UIImage imageNamed:@"4MakkelijkMoeilijkSaai.jpg"];}
    if(dimensie==3){
        filmAchtergrond0.image = [UIImage imageNamed:@"4VeiligGevaarlijkBeklemmend.jpg"];}
    if(dimensie==4){filmAchtergrond0.image = [UIImage imageNamed:@"4NormaalBijzonderSleur.jpg"];}
    if(dimensie==5){filmAchtergrond0.image = [UIImage imageNamed:@"4AlleenSamenEenzaam.jpg"];}
    if(dimensie==6){filmAchtergrond0.image = [UIImage imageNamed:@"4OrdeChaosRigide.jpg"];}
    }
    [arrowRight setImage:[UIImage imageNamed:@"ARROW_RIGHT_ACTIVE.png"] forState:UIControlStateNormal];
}

if(dimensie==1){headerPositie.image = [UIImage imageNamed:@"OUT1.png"];}
if(dimensie==2){headerPositie.image = [UIImage imageNamed:@"OUT2.png"];}
if(dimensie==3){headerPositie.image = [UIImage imageNamed:@"OUT3.png"];}
if(dimensie==4){headerPositie.image = [UIImage imageNamed:@"OUT4.png"];}
if(dimensie==5){headerPositie.image = [UIImage imageNamed:@"OUT5.png"];}
if(dimensie==6){headerPositie.image = [UIImage imageNamed:@"OUT6.png"];}
}
Pip
  • 159
  • 2
  • 9
  • You should show the code and any error messages. The iPad 1 has half the RAM of the iPad 2 and I have found it to be intolerably slow. You might consider dropping support for it. – woz Mar 30 '13 at 19:53
  • 1
    You should run the app with your iPad 1 connected with Xcode and set an exception breakpoint. This will help you to figure out why it's crashing. – Jeff Wolski Mar 30 '13 at 19:53
  • 2
    woz, I aim for 6.1 and that's no ipad 1. Yet, I have one myself and to test an app, I have to do it with that. That being so, I prefer to have it working on my ipad just as a proof of soundness. I don't want to lean on more RAM even if it is easily available, when in fact my design is not sober enough and can be more innovative or economically fixed. This goes up high, as one can imagine a whole technical culture leaning on more RAM versus a culture that has to do with less but in the end proves to be more effectively as they learn to improve their coding instead. USA vs Russia in the '80s? – Pip Mar 30 '13 at 20:37
  • I've added the esential code, where the overload happens. I hope one sees a huge pile of memory and point me out my amateuristic blindness with patience so that I can learn from this to be a better programmer. – Pip Mar 30 '13 at 20:38
  • I've ran with an exception breakpoint. I guess it just works as you define it, without a location or so as usually with breakpoints. Anyway it says: Low Memory Warning. – Pip Mar 30 '13 at 20:45
  • 1
    Why wasn't 'imageContentsOfFile' working? Generally you do: NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"fileExtension"]; UIImage *img = [UIImage imageWithContentsOfFile:filePath]; – LK__ Mar 30 '13 at 20:50
  • Okay, I will try again. I'll make filepath a universal/global variable. – Pip Mar 30 '13 at 20:53
  • Oh, no, it has to be set every time. Well, that generates a lot of doubles... I hope it's worth the effort. I hope it solves the big heap that is so unbearable for my ipaddie. – Pip Mar 30 '13 at 20:55
  • what has to be set every time? – LK__ Mar 30 '13 at 21:16
  • Okay, the operation has worked out quite fine. It is solved with a working application of the imageWithContentsOfFile ruling out the imageNamed stuff. – Pip Mar 30 '13 at 21:23
  • the filepath (has to be set every time), for every name is unique – Pip Mar 30 '13 at 21:23
  • How do I finish here? How can I mark with that green V? – Pip Mar 30 '13 at 21:25
  • Ik, can you post an answer so I can approve that as correct? – Pip Mar 30 '13 at 21:26

1 Answers1

0

Load the images using UIImage imageWithContentsOfFile:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"fileExtension"]; 
UIImage *img = [UIImage imageWithContentsOfFile:filePath];

See here the difference between imageNamed and imageWithContentsOfFile:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html

LK__
  • 6,515
  • 5
  • 34
  • 53