iPhone SDK:3.0是否清除imageNamed的缓存?因为2.2.1不会! [英] iPhone SDK: Does 3.0 clear the cache of a imageNamed? Because 2.2.1 doesn't!

查看:42
本文介绍了iPhone SDK:3.0是否清除imageNamed的缓存?因为2.2.1不会!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone创建一个应用程序,其中涉及一个以上的按钮,它们都为同一个UIImageView设置动画.它在模拟器中效果很好(几乎与所有应用程序一样),但是当涉及到设备时,它可以很好地播放动画,但是通过重复按下按钮可以退出该应用程序.到目前为止,我已经实现了2个按钮.这是当按下它们时会发生的情况.好的,我的应用启动时我有44 MB的可用内存,然后当我按下启动动画的2个按钮中的第一个时,可用内存下降到31并上升到32,然后当我按下第二个按钮时,可用内存下降到9,然后上升到24,然后奇怪地缓慢下降到10.如果然后按下第一个按钮,则可用内存将增加到14MB,并且在重复按下这些按钮后,应用程序的内存将下降到4到3 MB并退出.仪器中没有泄漏.这是我的代码,以防任何人都能发现我的内存问题潜伏的地方.(顺便说一句,我仍然在2.2.1上进行开发,因为如果我升级到3.0,我将无法在设备上测试我的应用程序,因为我还没有参加Apple开发人员计划,所以我遵循了在线教程来获取只能在2.2.1上运行的设备上的应用程序)

I am creating an application for the iPhone which involves having more than one button which all animate the same UIImageView. It works well in the simulator, (like practically all apps) but when it comes to the device it plays the animation well, but with repetitive pressing of the buttons the app quits. So far I have implemented 2 buttons. Here's what happens when they are pressed. Okay, I have 44 MB of ram available when my app starts, Then when I press the first of 2 buttons that start an animation the available memory goes down to 31 and climbs up to 32, then when I press the second button the available memory goes down to 9 then climbs to 24 and then strangely declines to 10 slowly. If the first button is then pressed then the available memory climbs to 14MB And under repetitive pressing of these buttons the apps memory goes down to 4 to 3 MB and quits. In instruments there are no leaks. Here is my code incase anyone can spot where my memory issue lurks. (BTW, I'm still developing on 2.2.1 because if I upgrade to 3.0 i won't be able to test my apps on the device as I am not enrolled in the apple developer program yet and I followed an online tutorial to get apps onto the device that only works with 2.2.1)

 @synthesize 123pig;
    - (IBAction)startClick:(id)sender{
    animationTimer = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick) userInfo:nil repeats:NO];

        123pig.animationImages = [NSArray arrayWithObjects:
                                [UIImage imageNamed: @"123pigapple0001.png"],
                                 [UIImage imageNamed: @"123pigapple0002.png"],
                                 [UIImage imageNamed: @"123pigapple0003.png"],
                                 [UIImage imageNamed: @"123pigapple0004.png"],
                                  [UIImage imageNamed: @"123pigapple0005.png"],
                                  [UIImage imageNamed: @"123pigapple0006.png"],
                                  [UIImage imageNamed: @"123pigapple0007.png"],
                                  [UIImage imageNamed: @"123pigapple0008.png"],
                                  [UIImage imageNamed: @"123pigapple0009.png"],
                                  [UIImage imageNamed: @"123pigapple0010.png"],
                                  [UIImage imageNamed: @"123pigapple0011.png"],
                                  [UIImage imageNamed: @"123pigapple0013.png"],
                                  [UIImage imageNamed: @"123pigapple0014.png"],
                                  [UIImage imageNamed: @"123pigapple0015.png"],
                                  [UIImage imageNamed: @"123pigapple0016.png"],
                                  [UIImage imageNamed: @"123pigapple0017.png"],
                                  [UIImage imageNamed: @"123pigapple0018.png"],
                                  [UIImage imageNamed: @"123pigapple0019.png"],
                                  [UIImage imageNamed: @"123pigapple0020.png"],nil];

        [123pig setAnimationRepeatCount:1];
        123pig.animationDuration =.7;
        [123pig startAnimating];
}

    - (void)tick{
    [self animatePig];
}

    - (void)animatePig{

    UIImage *pigImage13=[UIImage imageNamed:@"123pigapple0020.png"];


    if(123pig.image == pigImage13)
        123pig.image = pigImage13;
    else
        123pig.image = pigImage13;






    }
    - (IBAction)startClick1:(id)sender{
    animationTimer1 = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick1) userInfo:nil repeats:NO];
        123pig.animationImages = [NSArray arrayWithObjects:
                              [UIImage imageNamed: @"123pig0015.png"],
                              [UIImage imageNamed: @"123pig0016.png"],
                              [UIImage imageNamed: @"123pig0017.png"],
                              [UIImage imageNamed: @"123pig0018.png"],
                              [UIImage imageNamed: @"123pig0019.png"],
                              [UIImage imageNamed: @"123pig0020.png"],
                              [UIImage imageNamed: @"123pig0021.png"],
                              [UIImage imageNamed: @"123pig0022.png"],
                              [UIImage imageNamed: @"123pig0023.png"],
                              [UIImage imageNamed: @"123pig0024.png"],
                              [UIImage imageNamed: @"123pig0025.png"],
                              [UIImage imageNamed: @"123pig0026.png"],
                              [UIImage imageNamed: @"123pig0027.png"],
                              [UIImage imageNamed: @"123pig0028.png"],
                              [UIImage imageNamed: @"123pig0029.png"],
                              [UIImage imageNamed: @"123pig0030.png"],
                              [UIImage imageNamed: @"123pig0031.png"],
                              [UIImage imageNamed: @"123pig0032.png"],
                              [UIImage imageNamed: @"123pig0033.png"],
                              [UIImage imageNamed: @"123pig0034.png"],
                              [UIImage imageNamed: @"123pig0035.png"],
                              [UIImage imageNamed: @"123pig0036.png"],
                              [UIImage imageNamed: @"123pig0037.png"],
                              [UIImage imageNamed: @"123pig0038.png"],
                              [UIImage imageNamed: @"123pig0039.png"],
                              [UIImage imageNamed: @"123pig0040.png"],
                              [UIImage imageNamed: @"123pig0041.png"],
                              [UIImage imageNamed: @"123pig0042.png"],
                              [UIImage imageNamed: @"123pig0043.png"],
                              [UIImage imageNamed: @"123pig0044.png"],
                              [UIImage imageNamed: @"123pig0045.png"],
                              [UIImage imageNamed: @"123pig0046.png"],
                              [UIImage imageNamed: @"123pig0047.png"],
                              [UIImage imageNamed: @"123pig0048.png"],

                              nil];

    [123pig setAnimationRepeatCount:1];
    123pig.animationDuration =2.7;
    [123pig startAnimating];


      }
    - (void)tick1{
        [self animatePig1];
    }

    - (void) animatePig1{

        UIImage *pigImage11=[UIImage imageNamed:@"123pig0048.png"];


        if(123pig.image == pigImage11)
            123pig.image = pigImage11;
        else
            123pig.image = pigImage11;






    }
    - (void)stopTimer
    {
    [animationTimer invalidate];
    [animationTimer release];
    [animationTimer1 invalidate];
    [animationTimer1 release];
    }







    -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    123pig.center = location; 
    }

    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    }



    - (void)dealloc {
    [super dealloc];
    [123pig release];
    }
@end

我有一个想法是导致imageNamed的原因,并且即使在出现内存警告后2.2.1也不会清除它的缓存,在另一个SO问题上,有人说我的理解是+ imageNamed:缓存应该尊重内存iPhone OS 3.0上发出警告.如果有机会,请对其进行测试,如果发现情况并非如此,请报告错误."现在,即使我确实下载了3.0版的固件和SDK,也不知道它是否正在清除imageNamed的缓存,因为我无法在设备上对其进行测试!顺便说一句,请记住我是iPhone SDK的新手.预先感谢.

I have an idea that it's imageNamed thats causing it and that 2.2.1 doesn't clear it's cache even after a memory warning, and on another SO question someone said "My understanding is that the +imageNamed: cache should respect memory warnings on iPhone OS 3.0. Test it when you get a chance and report bugs if you find that this is not the case." Now even if i did download the firmware and SDK of 3.0 I wouldn't know if it was clearing the cache of imageNamed because I wouldn't be able to test it on a device! BTW when answering keep in mind that I am new to The iPhone sdk. Thanks in advance.

----------------编辑----------------我刚刚被苹果iphone开发人员计划所接受.OO,我将检查3.0是否正确释放了缓存的图像.

----------------Edit---------------- I've just been accepted into the apple iphone developer program. WOOOHOOO, I'll check if 3.0 releases cached images properly.

-------------编辑------------------是的,它不会释放缓存的图像.请在下面查看我的答案以进一步说明.

-------------Edit------------------ Yes it does release cached images. Check my answer below for further clarification.

推荐答案

好的,人们看来,iPhone OS 3.0确实清除了确实收到内存警告命令的缓存图像,呜呼!我1,Xcode0.更多细节:在iPhone os 2.2.1中,当您释放动画图像视图时,不会释放缓存的图像,因此,如果您的应用程序包含大量动画,则iPhone最终将用尽记忆并退出.因此,您只需要研究其他更复杂的动画方法,并且如果他们可以避免的话,谁也不想这样做.但是现在发布确实清除了缓存!我可以说是因为当我在应用程序中按一个按钮为视图设置动画时,要等到动画播放时才稍等,然后再按一次就没有等待了(因为它已缓存了),但是如果按了另一个按钮对该视图进行动画处理,将释放以前的缓存动画!因此,按下第一个按钮会给您带来原始的等待,因此我现在可以放松并继续进行开发,而不是尝试解决可能导致苹果故障的内存管理问题.

Okay people, It would seem that iPhone OS 3.0 does clear cached images on a did receive memory warning command, wooohooo! Me 1, Xcode 0. A bit more detail: In the iPhone os 2.2.1 when you release an animated Image view, the cached images aren't released, so if your app had loads of animations then eventually the iPhone would run out of memory and quit. So you would just have to go into other more complex methods of animation, and no one wants to do that if they can avoid it. But now releasing does clear the cache! I can tell because when I press a button in my app to animate a view there's a bit of a wait until the animation plays, then if that is pressed again there is no wait (because it cached it) But then if you press another button that animates that view, the previous cached animation is released! So pressing the first button gives you that original wait, so I can relax now and get on with developing rather then trying to fix a memory management issue that boils down to be apples fault.

这篇关于iPhone SDK:3.0是否清除imageNamed的缓存?因为2.2.1不会!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆