WKInterfaceController.reloadRootPageControllers has a memory leak?

Hi everyone,

Noticed that if you're passing more than 1 context with the same object through reloadRootPageControllers function in WKInterfaceController the passed context will never be deallocated from memory.

For example:
Code Block
let context = Context(name: "context")
WKInterfaceController.reloadRootPageControllers(withNames: ["first", "second"], contexts: [context, context], orientation: .horizontal, pageIndex: 0)

context will never be deallocated.

Source Code of the project which reproduces this issue.
Screenshot which shows zombie objects from the memory graph.

How to resolve it? Thanks in advance.

Replies

Also got this issue with different objects passed in contexts, watchOS 7.0
Could bypass this bug by creating singleton and requiring data from it and passing nil to contexts in reloadRootPageControllers method. awakeWithContext in your controller is called in right sequence from first page to the last, so you can retrieve data from singleton in this method and delete requested model right after you retrieve it. Sorry for my English, hope I helped someone.



Продублирую на русском, на нем явно лучше объясню. Судя по всему утечка памяти возникает В ЛЮБОМ случае, если использовать больше чем один контекст. Потому единственное решение - не передавать контексты в метод reloadRootPageControllers вообще. Я завел для этих целей специально синглтон, которому передаю данные, а потом вызываю у него метод получить данные из метода контроллера awakeWithContext для одной страницы. В этом методе соответсвенно выдаются данные ТОЛЬКО для одной страницы и тут же эти данные удаляются, поэтому при вызове этого метода второй раз (соответственно из второй страницы) уже будут получены для второй страницы и так далее. Таким образом, получая данные для последней страницы локальный Кеш в синглтоне полностью будет удален. Все это решение держится на том, что при вызове reloadRootPageControllers инициализируются сразу контроллеры для всех страниц и у всех поочередно вызываются awakeWithContext. Поэтому вся последовательность соблюдается и все, в целом работает. Но костыль жесткий, конечно
P.S. - I was wrong - awakeWithContext is called in right sequence for all pages ONLY on simulator. On real watches pages loaded dynamically for current page and neighbor on the right and on the left. Others loads during scroll. Anyway, algorithm to provide data is pretty simple
I have the same problem. This looks like a bug in watchOS. Is there a radar for it?