iOS 项目性能分析(用Xcode进行内存分析)
2019-02-23 本文已影响23人
H_vv
项目中的性能分析分为两种
先解释一下什么内存泄漏和内存溢出
内存泄漏:该释放的时候没有释放
内存溢出:简单说就是内存不够用。
1:静态分析
检测代码中是否有潜在的内存泄露。
编译器觉得不太合适的代码。
工具:Analyze


一般静态分析 Xcode 可能会暴露出很多问题,因为当编译器觉得不太合适的代码也会给你暴露出去,所以我们静态分析内存时针对性的对问题进行修改!
2:动态分析(instruments)
检测程序在运行过程中的内存变化
工具:Profile
Allocations:可以很清楚的知道APP的内存分配情况
Leaks:可以实时看到APP的内存泄漏(常用)

instruments: 是Xcode自带的工具 Xcode -> Product ->Profile 运行 instruments。

双击和点击choose 都可以打开调试 ,项目中Allocations和Leaks几乎就满足,也看自己的需要检测和使用其它的工具

All Heap Allocations 程序启动占用的内存 每个都有 看heap就知道是 堆内存
下面很多方法都是调用时占的内存,可以点击进去查看每个对象调用的内存(使用这个工具都是实时观看内存变化)


Xcode 基本的内存就分析这些,大家了解一下 ,预防面试。。。