ARC 和 MRC 之间的区别
我对苹果材料感到困惑。
我们通过三种方式管理内存,它们是:
- 自动引用计数。
- 手动引用计数。
- 垃圾收集。
我的疑问是自动引用计数和手动引用计数有什么区别。
有人能给我解释一下吗?
I am confused with Apple material.
In 3 ways we manage the memory, they are :
- automatic referance counting.
- manual reference counting.
- garbage colletion.
My doubt is what is the difference between automatic reference counting and manual referance counting.
Can someone explain me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 ARC 中,您不必释放/自动释放您分配的内存,而在手动情况下,您必须处理这一点。
例如手动外壳
ARC 外壳
In ARC you don't have to release/autorelease the memory allocated by you where as in case of manual you have to take care of this.
e.g. manual case
ARC case
在 ARC 中,操作系统负责内存管理,因此您不必担心释放对象。对于初学者来说这非常整洁。而在手动计数中,您必须跟踪内存的释放情况,如果做得不正确,您最终将导致应用程序崩溃。 ARC 和 MRC 在 ios 中可用,因为垃圾收集仅限于 MAC-OSX 希望这会有所帮助。因德尔给出了一个很好的例子。
In ARC the OS looks after the memory management, so you don't have to worry about releasing the objects. It's pretty neat for beginners. Whereas in Manual counting you will have to keep track of releasing the memory and if you don't do it right you will end up crashing your app. ARC and MRC are available in ios where as garbage collection is limited to MAC-OSX hope this helps. Inder has given a good example.
在 MRC 中,您负责跟踪并确保对象的所有引用都正确递增、递减和释放。在 Obj-C 中,你基本上有一套规则来帮助你避免任何内存泄漏或悬空指针,并且需要付出相当大的努力才能确保一切正常运行,并且这可以通过某些东西来自动化,例如某些其他语言习惯。
这就是 ARC 发挥作用的时候。
ARC 是 MRC 工作方式的一个深刻替代方案。使用 ARC,当没有对实例的强引用时,实例将被释放,并且每个实例都会跟踪自身保留的强引用和弱引用/无主引用的数量。虽然它可能看起来像类似的行为,但两种情况下使用的工作量却有很大不同,在 MRC 中您必须跟踪所有内容,而在 ARC 中您唯一应该做的就是避免保留循环。
ARC 和垃圾收集器之间的一些区别是:
如果您想了解更多信息,我发现这篇文章非常有帮助:https://swift007blog.wordpress.com/2017/01/14/what-is-arc-in-ios/
In MRC, you were responsible for keeping track and making sure that all references of objects were incremented, decremented and deallocated properly. In Obj-C you have basically a set of rules to help you not get any memory leaks or dangling pointers, and it was a considerable effort to make sure that everything was working great, and that could've been automated by something, like some other languages used to.
That's is when ARC get's into the game.
ARC came as an incisive alternative to how things worked with MRC. With ARC, instances are deallocated when there's no strong reference to them, and every instance keeps track of the number of strong and weak/unowned references kept to itself. Although it might look like a similar behaviour, the amount of effort used in both cases are hugely different, in MRC you had to keep track of everything, whereas in ARC the only thing you should do is avoid retain cycles.
Some differences between ARC and Garbage Collector are:
If you want to check for more information, I've found this article to be very helpful:https://swift007blog.wordpress.com/2017/01/14/what-is-arc-in-ios/
MRC 与 ARC
ARC
在<中插入retain
、release
、autorelease
而不是developer强>编译时间。现在您不必担心手动内存管理[底层]
MRC vs ARC
ARC
insertsretain
,release
,autorelease
instead of developer in compile time. Now you don't worry about manual memory management[Under the hood]