Today Widget: Memory Issue

I'm running into memory issues on iOS 10 when the widget is in expanded mode. Going away from the screen and coming back will recreate the widget VC is expected. However, the old Widget ViewController will not get removed from memory.


I have been able to trace this down to a constraint constant change when the collection view layout is prepared. If I remove that constant change, the VC will get removed from memory. Is this expected?

This is not expected. :-) It sound like you've created a retain cycle somehow. Can you show us the code which seems to cause the issue?


Dirk

Here's a sample project I created for Radar: https://www.dropbox.com/s/npzapfy510em0t2/TestMemoryLeak.zip?dl=0

Here are the steps I listed on the radar:


1. Be in Expanded Widget mode on iOS 10

2. Have UIView with a UICollectionView subclass

3. UIView has a height constraint

4. Listen for collectionView.contentSize changes

5. In KVO callback, change height constraint

6. Swipe away from Widget screen and come back

7. When a new Widget VC is created, notice that the old Widget VC never gets deallocated

8. Switch to Compact Mode

9. Notice that Widget VC starts to get deallocated

10. Between 8 and 9, I start seeing leaks in Instruments.




One other thing I noticed was that setting the last known height in viewDidLoad solved the memory issue.

So my post isn't being shown due to moderation with a link so here are steps to reproduce that I included in the radar (#28397517). @just.do.it, I can also provide a sample project reproducing this issue if you email my gmail (my user name). (Sorry, not including any possible links at risk of moderation 😀)


1. Be in Expanded Widget mode on iOS 10

2. Have UIView with a UICollectionView subclass

3. UIView has a height constraint

4. Listen for collectionView.contentSize changes

5. In KVO callback, change height constraint

6. Swipe away from Widget screen and come back

7. When a new Widget VC is created, notice that the old Widget VC never gets deallocated

8. Switch to Compact Mode

9. Notice that Widget VC starts to get deallocated

10. Between 8 and 9, I start seeing leaks in Instruments.

Send you an email. :-)

Dirk

Thanks @just.do.it! I haven't received an email at jml5qh@gmail.com - just confirming the spelling.

Still seeing this on the last iOS 10 builds. However, I would note that this is quite a bit easier to reproduce than the 9 steps above. I get to step 9 simply by engaging memory warnings sometimes. The memory limit on widgets seems to be comically/absurdly low. It's called Virtual Memory guys, read all about it. A hard limit of ~10MB was low in the 1980s.


As a workaround, I am walking every single subview and removing all views in viewDidLoad before I setup my UI. AFAICT that seems to work to get rid of the old UI caused by the iOS 10 bug.

Today Widget: Memory Issue
 
 
Q