iphone项目 浏览100张卡片 老是crash  为什么啊  是内存不够吗?大侠们 帮帮我

解决方案 »

  1.   

    贴上crash异常信息看看才知道
      

  2.   

    怎么个浏览法?贴个consol上吧,可能是内存不够导致的crash。
      

  3.   

    unable to read unknown load command 0x26
    warning: UUID mismatch detected with the loaded library - on disk is:
    /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0.1 (9A405)/Symbols/System/Library/Extensions/IMGSGX535GLDriver.bundle/IMGSGX535GLDriver
    unable to read unknown load command 0x25
    unable to read unknown load command 0x26
    gdb-arm-apple-darwin(1358,0xa0483540) malloc: *** mmap(size=24268800) failed (error code=12)
    *** error: can't allocate region
    *** set a breakpoint in malloc_error_break to debug
    gdb stack crawl at point of internal error:/SourceCache/gdb/gdb-1510/src/gdb/utils.c:1200: internal-error: virtual memory exhausted: can't allocate 24267986 bytes.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.The Debugger has exited with status 1.The Debugger has exited with status 1.
      

  4.   

    [code=C/C++][/code- (void)setCards:(NSMutableArray *)value {
    _cards = value; 
    UIImage * imgDefault = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
    for(int i = 0;i<[_cards count];i++){
    Card *card = [_cards objectAtIndex:i];
    NSArray *temp = [card.front componentsSeparatedByString:@"."]; 
    GLuint defaultTexture = [self imageToTexture:imgDefault];
    GLuint texture1;
    if ([card.front isEqualToString:@"Default.png"]) {
    texture1 = defaultTexture;
    }
    else {
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[temp objectAtIndex:0] ofType:[temp objectAtIndex:1]]];
    texture1 = [self imageToTexture:img];
    [img release];
    }
    FlowCoverRecord *fcr = [[FlowCoverRecord alloc] initWithTexture:texture1];
    NSNumber *num = [NSNumber numberWithInt:i];
    [cache setObject:fcr forKey:num];
    [fcr release];
    }
    [imgDefault release];
    [self performSelectorInBackground:@selector(loadOtherCards) withObject:nil];
    }/*
     *  Load Other cards
     */
    - (void)loadOtherCards{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];
    //Load other cards
    NSLog(@"load othercards");
    //A flag used to judge whether other card is loaded.
    BOOL flag = NO;

    Card * defaultCard = [_cards objectAtIndex:[_cards count]-1];
    if ([defaultCard.front isEqualToString:@"Default.png"]){
    flag = YES;
        for (int i =3; i < [_cards count]; i++) {

    Card *card = [[Card alloc] init];
    card.cardID = i;

    if(i<9){
    card.front = [NSString stringWithFormat:@"%@0%d.png",CARDFRONT_PREFIX,i+1];
    card.back = [NSString stringWithFormat:@"%@0%d.png",CARDBACK_PREFIX,i+1];
    }else{
    card.front = [NSString stringWithFormat:@"%@%d.png",CARDFRONT_PREFIX,i+1];
    card.back = [NSString stringWithFormat:@"%@%d.png",CARDBACK_PREFIX,i+1];
    }
    NSLog(@"card front : %@",card.front);
    [_cards replaceObjectAtIndex:i withObject:card];

    //If the other cards loading has not been fiinshed,then load and setCards.
    if (flag) {
    NSArray *temp = [card.front componentsSeparatedByString:@"."]; 
    GLuint texture;
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[temp objectAtIndex:0] ofType:[temp objectAtIndex:1]]];
    NSLog(@"111111111111");
    texture = [self imageToTexture:img];
    NSLog(@"2222222222222");
    [img release];
    FlowCoverRecord *fcr = [[FlowCoverRecord alloc] initWithTexture:texture];
    NSNumber *num = [NSNumber numberWithInt:i];
    [cache setObject:fcr forKey:num];
    [fcr release];
    int maxVisibleCount = floor(offset + 0.5) + VISTILES;
    if (i <= maxVisibleCount ) {
    [self performSelectorOnMainThread:@selector(draw) withObject:nil waitUntilDone:YES];
    }
    }
    [card release];
    }
    }
    else {
    flag = NO;
    }

    [pool release];
    }
      

  5.   

    恩  你好  我的项目是100张卡片   我要来回浏览   如果刚开始等等 的话  快速浏览页面就不会crash    如果一开始进入程序就狂拉页面    拉到后面就老是容易crash。。这个怎么弄啊 还有你说根据页面显示的张数加载  我的页面会显示5张   中间大的 两边前后各两个缩小放在边上   这个怎么弄呀?、谢谢啦
      

  6.   

    *** error: can't allocate region
    *** set a breakpoint in malloc_error_break to debug
    说的多清楚啊……
      

  7.   

    iOS动态开辟空间建议不超过20M,提倡打包为资源文件随用随取。
    相关代码参考 电子书 。