菜鸟教程小白 发表于 2022-12-12 20:04:29

objective-c - ARC引用计数dealloc和release


                                            <p><p>我有点困惑。我正在使用 Storyboard 创建一个应用程序,并在 iPad 1 上运行它。该应用程序使用了大量内存,因此达到了 120mb,崩溃了。据我所知,要消除这个问题,你需要释放,dealloc ...关键是ARC应该是自动的。事实上,如果我添加例如:;它给了我一个错误。但是这个ARC自动释放和dealloc似乎不起作用!这是因为 ARC 有不同的发布方式吗??</p>

<p> <img src="/image/lgXC0.png" alt="enter image description here"/> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您无需使用 ARC 手动保留/释放/自动释放。但是,如果您对许多未使用的对象有事件引用,它们仍将保留在内存中。使用 Instruments 分析您的应用程序,它将显示您为每个类创建了多少对象以及它们消耗了多少内存。</p>

<p>使用 ARC,您仍然需要考虑内存使用情况,而无需过多担心内存泄漏。</p>

<pre><code>NSObject *bigMemObj = [ init];
//This creates the object in memory. In both arc and manual counting the retain count is 1

//Do stuff

//Prior to ARC you would have had to call ; before setting the variable to nil
bigMemObj = nil
//With ARC you don&#39;t have to do anything. The compiler inserts the release at compile time
</code></pre>

<p>另请阅读有关声明 iVar __strong 与 __weak 的文档。</p>

<p>如果不查看您的代码,很难确定是什么消耗了所有内存,但希望这可以帮助您确定从哪里开始查找。</p></p>
                                   
                                                <p style="font-size: 20px;">关于objective-c - ARC引用计数dealloc和release,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/9932127/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/9932127/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: objective-c - ARC引用计数dealloc和release