Closed farfromrefug closed 4 years ago
Hi @farfromrefug, I managed to stably reproduce the issue by adding the following line to the createViewModel
function:
setInterval(__collect, 500);
This way each 500 ms there'll be a GC forcing any garbage objects to be collected.
After that, I discovered that the ShareFile
object is not kept alive by anything. When it was destroyed everything that it held references to became eligible for destruction as well (including the UIDocumentInteractionController
and UIDocumentInteractionControllerDelegateImpl
) and this is what caused the faulty behavior that you've observed.
In order to fix the issue, I changed the 1st argument to initWithOwnerController
to be a normal strong reference instead of the WeakRef
that was originally in the code. (A also had to modify the access to _owner
in UIDocumentInteractionControllerDelegateImpl
to not call _owner.get()
).
@mbektchiev wow thank you ! I will try and report succcess.
BTW can you tell me how you "saw" that ShareFile
was released. I was suspecting it but i had no tool to verify it.
I didn't use a tool for that as well. It would've been nice to be able to track that, but I don't know an easy way to do that. I just observed that it was not stored anywhere:
await new ShareFile().open({ path: file.path, title: fileName, options: true, animated: true });
doesn't assign it to anything outside. Then I noticed that it's the object that gets ownership of the delegate and controller objects and figured out it had to be strongly referenced somewhere but didn't find such a place. That's why I decided to change the weak reference to a strong one. This way, it will live as long as the delegate object is needed by the view controller.
@mbektchiev ok i got it. I actually thought it was "stored" because of the promise which was awaiting the full completion. Guess i was wrong. Thanks again will test that right now
I am using latest runtime, N and everything.
I have an issue with the
UIDocumentInteractionController
I use it hereNow my issue is a random failure. Failure in the sense that when i try to share with the mail for example the mail will have no attachment nor title. And i wont get delegate calls.
It is clearly a deallocating issue as explained here https://forums.developer.apple.com/thread/82952
Though what i don't get is that i keep a reference to the controller in the
ShareFile
object which should be kept until theopen
promise resolves. And if i understand correctly by doing that the runtime keeps a strong reference to the controller, right?I am quite lost here. That s why i am asking for help here. I simply cant tell if the issue comes from my code or somewhere else.
Also right now i dont have a simple code example as i use it in a prod client app. Also this is the relevent code: