smallcloudai / refact-intellij

Refact AI: Open-source AI Code assistant with autocompletion, chat, refactoring and more for IntelliJ JetBrains IDEs
https://refact.ai
BSD 3-Clause "New" or "Revised" License
31 stars 12 forks source link

com.smallcloud.refactai.modes.ModeProvider holds released Editor #126

Open ViugiNick opened 4 months ago

ViugiNick commented 4 months ago

Lambda in ModeProvider registered as MyScheduledFutureTask holds reference to a released editor that refers a number of disposed objects

(root): com.intellij.util.concurrency.AppDelayQueue$TransferThread
this$0: com.intellij.util.concurrency.AppDelayQueue
q: java.util.PriorityQueue
queue: java.lang.Object[]
[]: com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask
callable: java.util.concurrent.Executors$RunnableAdapter
task: com.smallcloud.refactai.modes.ModeProvider$$Lambda
arg$1: com.smallcloud.refactai.modes.ModeProvider
editor: com.intellij.openapi.editor.impl.EditorImpl
myPopupHandlers: java.util.ArrayList
elementData: java.lang.Object[]
[]: com.intellij.openapi.editor.impl.ContextMenuPopupHandler$Simple
myActionGroup: com.intellij.openapi.actionSystem.DefaultActionGroup
mySortedChildren: java.util.ArrayList
elementData: java.lang.Object[]
[]: com.intellij.diff.merge.MergeThreesideViewer$IgnoreSelectedChangesAction
this$0: com.intellij.diff.merge.MergeThreesideViewer (disposed)
(root): com.intellij.util.concurrency.AppDelayQueue$TransferThread
this$0: com.intellij.util.concurrency.AppDelayQueue
q: java.util.PriorityQueue
queue: java.lang.Object[]
[]: com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask
callable: java.util.concurrent.Executors$RunnableAdapter
task: com.smallcloud.refactai.modes.ModeProvider$$Lambda
arg$1: com.smallcloud.refactai.modes.ModeProvider
editor: com.intellij.openapi.editor.impl.EditorImpl
myCaretModel: com.intellij.openapi.editor.impl.CaretModelImpl (disposed)
(root): com.intellij.util.concurrency.AppDelayQueue$TransferThread
this$0: com.intellij.util.concurrency.AppDelayQueue
q: java.util.PriorityQueue
queue: java.lang.Object[]
[]: com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask
callable: java.util.concurrent.Executors$RunnableAdapter
task: com.smallcloud.refactai.modes.ModeProvider$$Lambda
arg$1: com.smallcloud.refactai.modes.ModeProvider
editor: com.intellij.openapi.editor.impl.EditorImpl
myView: com.intellij.openapi.editor.impl.view.EditorView (disposed)
reymondzzzz commented 4 months ago

Hi! I didn't get :D Could you share more details about problem?

ViugiNick commented 4 months ago

In the bug description I attached a few memory leaking paths. It looks like the task lambda in ModeProvider holds an instance of ModeProvider that holds released EditorImpl and retains disposed objects like MergeThreesideViewer, CaretModelImpl, EditorView

ViugiNick commented 4 months ago

ModeProvider is also referenced from java.util.concurrent.Executors$RunnableAdapter

this$0: com.intellij.util.concurrency.AppDelayQueue
q: java.util.PriorityQueue
queue: java.lang.Object[]
[]: com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask
callable: java.util.concurrent.Executors$RunnableAdapter
arg$1: com.smallcloud.refactai.modes.ModeProvider
editor: com.intellij.openapi.editor.impl.EditorImpl