ios - MPMediaItemPropertyArtwork 导致崩溃(奇怪的问题)
<p><p>运行“额外循环”之前的分配
<img src="/image/RpuLD.png" alt="allocations before running 'crashing' loop"/> </p>
<p>代码:</p>
<pre><code>// loading items to the array, there are no memory warnings after this is completed. The first allocations screenshot is after this code and before extra loop code.
NSMutableArray *albumCovers = [ init];
for (MPMediaQuery *query in queries) {
NSArray *allCollections = ;
for (MPMediaItemCollection *collection in allCollections) {
MPMediaItemArtwork *value = ;
UIImage *image = ;
if (image) {
;
}
}
}
}
_mediaCollections = ;
_albumCovers = ;
}
</code></pre>
<p>还有其他地方:</p>
<pre><code>// !!!!! extra loop - from here the memory starts to grow and never release
for (i=0; i< 800; i++) {
UIImage * coverImage = ;
; // exactly this line adds to the memory. with this line commented, there is no problem.
}
</code></pre>
<p>运行“额外循环”后的分配
<img src="/image/Ttdpp.png" alt="allocations before running 'crashing' loop"/> </p>
<p>澄清一下,在 only-obj-c 开启和系统库关闭的情况下调用堆栈(如果我打开它们,每个最重方法的最高 % 为 0.9%)
<img src="/image/7Ssls.png" alt="call stack after extra loop"/> </p>
<p>我做了一些研究,发现在 <a href="https://stackoverflow.com/questions/18994039/imageio-in-instruments" rel="noreferrer noopener nofollow">stackoverflow</a> ,这些 <code>VM:ImageIO_PNG_Data</code> 通常来自 <code></code>,但是如您所见,我不使用此方法,我只是获取引用来自 <code>MPMediaItemCollection</code>。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>问题是 UIImage 通常只保留一个 ref(CGImageRef),它很小。显示项目后,CGImageRef 被“注入(inject)”了信息。结果,这张 table 一直在增长。 </p>
<p>简单但不是最漂亮的解决方案是使用代码:</p>
<pre><code>NSArray = @; // where obj is custom NSObject and has a UIImage property
</code></pre>
<p>代替:</p>
<pre><code>NSArray = @; // where img is of UIImage type
</code></pre></p>
<p style="font-size: 20px;">关于ios - MPMediaItemPropertyArtwork 导致崩溃(奇怪的问题),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19182495/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19182495/
</a>
</p>
页:
[1]