IDE hangs on startup: "Possible Emitter memory leak detected. 880 listeners added."

-02-27T23:56:12.343Z root WARN at _event._event.Object.assign.maxListeners (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:3013148)
at d.createEditor (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:3613286)
at async d.createEditor (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:1872915)
at async d.getOrCreateWidget (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:2955404)
2024-02-27T23:56:17.105Z root WARN Possible Emitter memory leak detected. 880 listeners added. Use event.maxListeners to increase the limit (175). MOST frequent listener (353):
2024-02-27T23:56:17.105Z root WARN at _event._event.Object.assign.maxListeners (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:3013148)
at l.loadModel (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:7474045)
at async t.ReferenceCollection.getOrCreateValue (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:3102563)
at async t.ReferenceCollection.acquire (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:3102343)
at async u.getModel (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:7376966)
at async u.createMonacoEditor (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:7379206)
at async u.doCreateEditor (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:7377879)
at async u.doCreateEditor (file:///C:/Program%20Files/arduino%20ide/resources/app/lib/frontend/bundle.js:2:1887168)

Hi @markotime. When Arduino IDE is started, it opens the saved sketches that were open at the time of exit of the previous session. From the logs you shared, I can see that Arduino IDE is opening a sketch that contains a large number of code files in the root folder.

Arduino IDE opens each of the sketch code files in an editor tab, so when the sketch contains a large number of code files in the root folder, it takes a long time for Arduino IDE to open it. This might give the impression the IDE has gone into a permanent hang state because it doesn't give any indication of its progress on opening the files, but from my experiments I find that it does eventually finish loading and starts up fully as expected.

If you leave Arduino IDE running for five minutes or so, does it eventually finish starting?


Examples of sketches that contain many files in the root folder:

Thank you, didn't see this. I think it spun for an hour or so, no load. i'll check again.

Still spinning after almost an hour.

As a workaround, you can pass the path to a simple sketch as a command line argument. That will cause Arduino IDE to open that sketch instead of attempting to restore the problematic sketch. After that, you will be able to start Arduino IDE normally since the problematic sketch will no longer be the sketch it attempts to load on startup.

I'll provide instructions you can follow to do that:

  1. Close all Arduino IDE windows if the IDE is already running.
  2. Start Windows "File Explorer".
  3. Open the Arduino IDE installation folder in File Explorer:
    C:\Program Files\Arduino IDE
    
  4. In the folder listing of the Arduino IDE installation folder, hold the Shift key while clicking the right hand button on the mouse.
  5. From the context menu, click "Open PowerShell window here".
    Windows PowerShell will now open with the current directory set to the Arduino IDE installation folder.
  6. Type the following command:
    & ".\Arduino IDE" resources\app\lib\backend\resources\Examples\01.Basics\BareMinimum
    
  7. Press the Enter key.
  8. Wait for Arduino IDE to start up fully.
  9. Select File > Quit from the Arduino IDE menus.
  10. Start Arduino IDE normally.

Arduino IDE should now start up fully and work as expected. The workaround of starting Arduino IDE from the command line should no longer be necessary after this.

Thank you so much! Still wondering how that all happened...

Oh, my... Open Power SHell doesn't appear on the right.click menu....
?? thanks

Started powershell manually. entered "&.. line correctly, tried twice
tlo make sure,
goes into endless looop with memory leak warning, .... ??

It's <shift> plus rightclick :wink:

Yeah, that's what I was doing.

OK, third try lucky. IDE starts as normal. However,
Load Marlin.ino, the program I wish to modify, begets the forever
screen... I'll leave it
for an hour or so, but not hopeful. Thanks for your continued help!

I'm glad you are at least able to start Arduino IDE now. The problem with loading Marlin is unfortunate.

I had some troubles with opening Marlin versions 1.x in Arduino IDE 2.x some years ago, but trying to load it now via the File > Open menu in Arduino IDE, I don't have any real problems. It does take a minute or so to load fully, but the IDE remains functional during this time and I can see the loading progress through the steady addition of more and more editor tabs for each of the hundreds of files of the sketch. As I mentioned in post #2, my user experience is less friendly when Arduino IDE automatically loads Marlin 1.x on startup due to it having been open at the time I exited the previous IDE session, but the IDE does start up and functions fine if I am just patient and wait for it to finish loading the sketch.

Between the time when I had the problems loading Marlin, in addition to Arduino IDE 2.x having received many improvements and fixes, I upgraded from what was a pretty outdated computer to one with moderately high end specs. It might be that a computer with lower specs simply doesn't have the significant resources that are required to open such a massive sketch.

Can you provide a link to where you downloaded your Marlin from? I am assuming that you are using an older version of Marlin. In Marlin 2.x, the hundreds of internal code files of the sketch were moved to a subfolder. This means that when you open a 2.x version of Marlin in Arduino IDE, it only has to load four files, which occurs almost immediately. The other files from the subfolder are only opened on demand so they shouldn't have any impact on the performance of the IDE application. If you were able to update to using the modern version of Marlin, I think the problems would no longer occur. I don't know whether such an update is feasible for you though.

Thank you. That was 2.1.2.1. From github. Now have 2.1.2.2, opens and
compiles, but
since config files are not compatible, I have a few hours work. Will not
start
my 2.1.2.1 work; 2 versions, one with bltouch, other without. I did
notice that
there are a zillion little files in my directory, and they occasionally
showed up
in the header of the ide, but not always. when present, compile took an
hour. Likely
reponsible for my loading issues.
Thank you so muc for your help and non-judgemental support for this
self-taught
octogenarian.

Ah. I'm surprised. The improvement I mentioned in my previous reply was made at the start of the 2.x series of Marlin.

For example, If you look at the contents of the Marlin folder at version 1.1.9.2:

You can see that it contains hundreds of code files in the root of the folder. Each of those files are opened in a separate editor tab in Arduino IDE when you open that version of the Marlin sketch, which takes a tremendous amount of computing resources.

Now look at the contents of the folder at the version 2.1.2.1 you were having problems with:

There are only four code files, which means Arduino IDE only has to create four tabs when you open that version of Marlin. All the other files have been moved under the src subfolder:

The code files there are still compiled as part of the sketch program, but Arduino IDE doesn't open editor tabs for them by default, so they don't impact the sketch load time (only the compilation time).

That is unfortunate. The suggestion I made in my previous reply of updating Marlin was based on the assumption you were using one of the 1.x versions, which have this known problem with load time. But since you were already using a 2.x version of Marlin, I do think we can find a way to get 2.1.2.1 working for you if you don't want to update.

Are they directly in the root of the Marlin folder, or are they under the src subfolder of the Marlin folder?

I'm glad if I can be of assistance. I'm sorry the experience of using Marlin with Arduino IDE 2.x hasn't been as smooth as we would have hoped.

It is very cool that you are working with 3D printers! Despite having been working with Arduino for over a decade, supporting many Marlin users and even making some trivial contributions to the project, I still haven't ever used a 3D printer or even seen one in real life.