• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ios > ios开发遇到的内存过大的问题

ios开发遇到的内存过大的问题

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-06-05

佚名通过本文主要向大家介绍了ios10占多少内存,ios10占用多少内存,ios10怎么清理内存,ios怎么清理内存,ios内存清理等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: ios开发遇到的内存过大的问题
描述:

import "memoryViewController.h"

import <BmobSDK/Bmob.h>

import "memory.h"

@interface memoryViewController (){

NSMutableArray *theMemory;
NSMutableArray *theHeadPicture;
UIImage * headPicture;

}
@property (weak, nonatomic) IBOutlet UITableView *memoryTableView;

@end

@implementation memoryViewController

pragma mark -- table datasource --

//设置table行数。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

if([theMemory count]==0)
    return 4;
else {
    NSLog(@"输出%lu行",(unsigned long)[theMemory count]);
    return [theMemory count];
    
}

}
//设置table section数.
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 1;

}
//cell
-(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

@autoreleasepool {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"memoryCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"memoryCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//设置点击cell后的风格
    //configure the cell
    
    if([theMemory count]==0){//加载前
        //主题
        UILabel *headlineLabel = (UILabel *)[cell viewWithTag:1];
        headlineLabel.text = @"正在加载";
        headlineLabel.textColor = [UIColor blackColor];
        //时间
        UILabel *dayLabel = (UILabel *)[cell viewWithTag:2];
        dayLabel.text =@"正在加载";
        dayLabel.textColor = [UIColor blackColor];
    }
    else{//加载后
        memory *aMemory = [[memory alloc]init];
        aMemory =[theMemory objectAtIndex:indexPath.row];
        
        //主题标签
        UILabel *headlineLabel = (UILabel *)[cell viewWithTag:1];
        headlineLabel.text = aMemory.headline;
        headlineLabel.font = [UIFont fontWithName:@"Helvetica" size:30];
        headlineLabel.textColor = [UIColor whiteColor];
        //时间标签
        UILabel *dayLabel = (UILabel *)[cell viewWithTag:2];
        dayLabel.text = [NSString stringWithFormat:@"%@",aMemory.createdAt];
        dayLabel.textColor = [UIColor whiteColor];
        
        //背景
        UIView *testView = [[UIView alloc]init];
        _imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
        NSLog(@"%@",_imgView);
        NSURL *theUrl = [NSURL URLWithString:aMemory.picture1];
        _imgView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:theUrl]];
        [testView addSubview:_imgView];
        cell.backgroundView = testView;
        //在cell里面设置view。向View里面添加UIImageView
    }
    return cell;
}

}

pragma mark --table delegate --

-(void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath{

[self performSegueWithIdentifier:@"showMemoryDetail" sender:self];

}

pragma mark --getdata --

//获取全部原始数据添加到theMemory里。通过theMemory数组提取出各个cell所需要的信息。
-(void)getData{

@autoreleasepool {
    
    BmobQuery   *bquery = [BmobQuery queryWithClassName:@"memory"];
    //查找GameScore表的数据
    [bquery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        for (BmobObject *obj in array) {
            //打印playerName
            memory *aMemory = [[memory alloc]init];
            aMemory.createdAt = [obj objectForKey:@"createdAt"];
            aMemory.headline = [obj objectForKey:@"headline"];
            BmobFile *photo = [obj objectForKey:@"picture1"];
            NSString *thephoto = photo.url;

// NSURL *url = [NSURL URLWithString:thephoto];
// UIImage * aHeadPicture = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];
// aMemory.picture1 =aHeadPicture;
// [theMemory addObject:aMemory];

            aMemory.picture1 = thephoto;
            [theMemory addObject:aMemory];
        }
        [self.memoryTableView reloadData];
    }];
    
}

}

  • (void)viewDidLoad {

    
    [super viewDidLoad];
    theMemory = [NSMutableArray array];
    theHeadPicture = [NSMutableArray array];
    [self getData];
    // Do any additional setup after loading the view.

    }

  • (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

    }

异步加载tableViewCell后内存过高,不知道问题出在哪里。我一步一步的检测代码都内存都没有增加,但是一运行起来内存就突然增高。初学者在自己尝试着,有没有知道哪里出问题的呢?我用instruments测试了没有内存泄漏。


解决方案1:

Image的设置有问题吧 为什么拿到URL之后要转换成NSData然后在转换成Image呢,如果是网络图片的话这种操作的确存在内存峰值的问题

解决方案2:

leak一定会检测出来,你要不断地测试你的app


分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • ios开发遇到的内存过大的问题

相关文章

  • 2017-06-05 为什么forin不能在按钮触发函数里?
  • 2017-06-05 读取文件iOS持久化,读取本地文件数据导致程序崩溃
  • 2017-06-05 ios使用afnetworking上传文件经常上传超时,但是重新上传又可以,在线求大神
  • 2017-06-05 android服务运行状态UIStackView运行后无法正确的显示布局
  • 2017-06-05 不用webview怎么引用jquery等文件吗???
  • 2017-06-05 前端开发:元素的点击时会产生黑色阴影层,ios设备会,安卓不会有
  • 2017-06-05 一个textView里面的内容高度明明比textview小,却还是会滑动的问题
  • 2017-06-05 关于Autolayout,子UILABEL控件不能控制父UIVIEW的高度
  • 2017-06-05 一些事一些情在线收听OC中定义一些常量及一些公共函数
  • 2017-06-05 使用Swift编写Framework在不同Xcode上使用报错

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • xcode81编译时,一直不动,也没有出现错误信息
    • 请教ios音乐播放时,界面动态显示图片的问题?动不起来我的图片。
    • Swift(swift)大家都是如何看开源代码的
    • yytext处理实现朋友圈回复效果
    • 当UIView正在做动画时,如何获取UIView的frame?
    • qq信息提示音ios提示信息的轮子
    • cruntimelibraryiOS如何使用runtime对富文本进行国际化
    • 工具栏里没有语言栏iOS导航栏与状态栏的坑
    • iOS关于信鸽推送的问题,怎么在生产环境下推送消息,表示app还没有发布上线,这个功能怎么测试
    • 正比例反比例iOS单例创建的一点疑惑

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有