As I start working in swift, I am curious in memory mgmt. As we all know that during any object creation or assignment of data into that object it takes memory. How can we check that a particular object has released the memory. I used xcode memory report to see memory status and fluctuations.
当我开始在swift工作时,我对内存管理很好奇。众所周知,在任何对象创建或将数据分配到该对象期间,它需要内存。我们如何检查特定对象是否释放了内存。我使用xcode内存报告来查看内存状态和波动。
Here is a sample of images:
这是一个图像样本:
How can release memory if I already set nil into the objects.
如果我已经将nil设置为对象,如何释放内存。
3 个解决方案
#1
3
Use instruments to track the lifecycle of an object than just Xcode because it gives you the allocation details at much higher level.
使用工具跟踪对象的生命周期而不仅仅是Xcode,因为它可以在更高的层次上为您提供分配细节。
Check out the answer at https://*.com/a/14891837/5133769. Though it was explained with old instruments it still works.
请访问https://*.com/a/14891837/5133769查看答案。虽然用旧仪器解释它仍然有效。
#2
1
Using instruments checking for leaks or allocations is the recommended way.
建议使用仪器检查泄漏或分配。
You can also set breakpoints or add logs to the dealloc method.
您还可以设置断点或将日志添加到dealloc方法。
#3
1
Some objects are very small and it could be difficult to see in Memory profiling which one is released. This tool is helpful for finding memory leaks in an app. To check was some object released from memory or wasn't you can setup breakpoints or logs in dealloc()
method for objective c and in deinit()
method for swift.
有些对象非常小,在Memory分析中可能很难看到哪一个被释放。此工具有助于在应用程序中查找内存泄漏。要检查某个对象是从内存中释放还是不是,您可以在目标c的dealloc()方法和swift的deinit()方法中设置断点或日志。
#1
3
Use instruments to track the lifecycle of an object than just Xcode because it gives you the allocation details at much higher level.
使用工具跟踪对象的生命周期而不仅仅是Xcode,因为它可以在更高的层次上为您提供分配细节。
Check out the answer at https://*.com/a/14891837/5133769. Though it was explained with old instruments it still works.
请访问https://*.com/a/14891837/5133769查看答案。虽然用旧仪器解释它仍然有效。
#2
1
Using instruments checking for leaks or allocations is the recommended way.
建议使用仪器检查泄漏或分配。
You can also set breakpoints or add logs to the dealloc method.
您还可以设置断点或将日志添加到dealloc方法。
#3
1
Some objects are very small and it could be difficult to see in Memory profiling which one is released. This tool is helpful for finding memory leaks in an app. To check was some object released from memory or wasn't you can setup breakpoints or logs in dealloc()
method for objective c and in deinit()
method for swift.
有些对象非常小,在Memory分析中可能很难看到哪一个被释放。此工具有助于在应用程序中查找内存泄漏。要检查某个对象是从内存中释放还是不是,您可以在目标c的dealloc()方法和swift的deinit()方法中设置断点或日志。