flutter-intellij icon indicating copy to clipboard operation
flutter-intellij copied to clipboard

[perf] Fix incorrect `parentDisposable`s

Open pq opened this issue 7 months ago • 3 comments

Using an Application or Project as a parent disposable in plugin code can lead to plugins not being unloaded correctly and with that memory leaks.

Image

See: https://plugins.jetbrains.com/docs/intellij/disposers.html?from=IncorrectParentDisposable#choosing-a-disposable-parent

pq avatar Apr 23 '25 21:04 pq

#8178 gets us nearly there but I'm not sure what to do about AndroidModuleLibraryManager which has a few registrations like this:

https://github.com/flutter/flutter-intellij/blob/0c1007c9ce05c39c284c1b29ef5c203a27cdb7bf/flutter-studio/src/io/flutter/android/AndroidModuleLibraryManager.java#L211

@alexander-doroshko: I wonder if you can advise? Are these Disposer registrations even necessary? If so, how would you migrate them?

pq avatar May 09 '25 20:05 pq

@pq Sorry for the delay. I can't answer this specific question right now. This question may disappear as soon as we start working on tech debt and the plugin refactoring.

General answer is that manual Disposer.register is very rarely needed. We try not to use the concept of Disposer/Disposables in new code at all.

So far, I don't fully understand the purpose of the AndroidModuleLibraryManager class. Extending and instantiating ProjectImpl (EmbeddedAndroidProject) looks suspicious by itself.

alexander-doroshko avatar May 15 '25 14:05 alexander-doroshko

General answer is that manual Disposer.register is very rarely needed. We try not to use the concept of Disposer/Disposables in new code at all.

I wondered about this and kind of gathered as much.

So far, I don't fully understand the purpose of the AndroidModuleLibraryManager class. Extending and instantiating ProjectImpl (EmbeddedAndroidProject) looks suspicious by itself.

Right. There are lots of internal dependencies in this class and TODOs going that suggest it may not be working as expected. Some dating back to 2018!

It looks like I was a reviewer on this so I'll try and jog my memory. For reference there's https://github.com/flutter/flutter-intellij/pull/2474

pq avatar May 15 '25 16:05 pq