菜鸟教程小白 发表于 2022-12-12 12:54:54

ios - Xcode 中的内存警告 - 在 didReceiveMemoryWarning 中做了什么?


                                            <p><p>我之前问过这个问题,但我认为我的问题没有被理解,所以这里又问了一遍:</p>

<p>我们不再处理内存,因为 ARC 会这样做。我们甚至不能调用内存释放命令等。那么如果代理收到内存警告通知,可以在运行时以编程方式解决内存警告问题吗?</p>

<p>我不想知道如何修复我的代码!!!
代码无法在运行时自行修复。</p>

<p>假设我已经正确编码,但仍然收到内存警告,可以做什么..</p>

<p>ie 你能举个例子说明什么是要编码到的</p>

<pre><code>- (void)didReceiveMemoryWarning
{
   ;
          // Release any cached data, images, etc that aren&#39;t in use.
   ;
}
</code></pre>

<p>方法?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>当然,您仍然可以控制内存。您只是在使用 ARC 在更高的抽象级别上进行操作。</p>

<p>您可以使用:<code>object = nil</code> 清除强引用。当所有强引用都被清除时,对象被释放。</p>

<p>如果您熟悉手动引用计数:</p>

<pre><code>object = nil; &lt;&lt; ARC
</code></pre>

<p>在自己做引用计数的时候是这样的:</p>

<pre><code>, object = nil;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Xcode 中的内存警告 - 在 didReceiveMemoryWarning 中做了什么?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/27043160/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/27043160/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Xcode 中的内存警告 - 在 didReceiveMemoryWarning 中做了什么?