How to Generate a Memory Leak in the Keyboard Maestro Engine

have been testing for only twenty minutes but here are my preliminary results.

  1. clicking on Enable/Disable group repeatedly does not make the Engine lose memory, at least not continually. It temporarily lost up to 20 MB from the baseline of 44 MB but that seems normal.

  2. enabling all my other macro groups caused the Engine to accelerate up to 900 MB but then fairly quickly dropped back down to 185 MB. I'm not sure if this is normal behavior or not.

  3. The KM Debugger rarely responds to my commands. It opened. 99% of the time when I click on something, like "Pause New Macros" it does nothing. It doesn't even close when I click on the (X). The icon in the upper right corner of the screen isn't responding to any clicks. At the start it seemed to be working but became unresponsive over time and is now frozen. There is one macro that appears to be "running" in the window and it's stuck on an innocuous "Speak Text" action. I would like to note that in Safe Mode the speakers are completely unavailable and I'm wondering if the Speak Text action is failing for that reason, causing the entire Engine to hang up. In the Activity Monitor the Engine is showing absolutely no change in memory (185.2 MB) or CPU usage (0%). The process is clearly hung. It does not say "not responding" however. So I will restart the Engine. I've restarted it. I opened the debugger. So far it's working. But there you go, it's refusing to process the Speak Text action again. It's not hung yet. But clearly in Safe Mode the Speak Text action is causing the debugger to freeze that action, while allowing other actions to continue. This could be normal for the KM Engine. I.e., without audio output drivers, the Engine may hang on audio statements. Aha! When I try to terminate one of the hung actions, the KM Engine totally hangs up. Now it even says "not responding" in the activity monitor., I restarted the Engine and repeated this. The engine always freeze and becomes unresponsive whenever I try to terminate a Speak Text action, which it can never execute.

I guess I can't accurately test the KM Engine until I remove all the Speak Text actions from my macros, which I use as debug statements. That will take a little time.

In the future I plan to create stubs for all actions in KM so that when I need to disable or modify it in some way, I have to edit only one location rather than hundreds.

OK, not what I was hoping to see. I hoped you could reproduce the issue, so that we could exclude that there are any third-party factors involved. Well, I hoped, but I did not expect to see it :wink:

With 20 minutes it was obviously not a complete test (see my PS), but I understand that with the Speak-action problems it might be difficult to continue.

However, your test already seems to point into one direction:

clicking on Enable/Disable group repeatedly does not make the Engine lose memory, at least not continually. It temporarily lost up to 20 MB from the baseline of 44 MB but that seems normal.

Assuming that in normal mode (not safe mode) the issue is clearly reproducible by enabling/disabling groups, it means there is indeed some interdependency with other processes or with some aspects of your normal system setup that triggers the memory leak.

enabling all my other macro groups caused the Engine to accelerate up to 900 MB but then fairly quickly dropped back down to 185 MB. I'm not sure if this is normal behavior or not.

I don’t know either if this is normal, but I would not call it alerting. If memory consumption spikes up for a short time and then drops back to something normal (like the 185MB) I would not speak of a leak in any way.

The KM Debugger rarely responds to my commands.

Do you have to use the debugger? (Did it trigger memory leaks in normal mode?)

I would like to note that in Safe Mode the speakers are completely unavailable

In safe mode all third-party kernel extensions, and probably also any other third-party “drivers”, are disabled. If you are using third-party drivers for your audio normally, then this would explain it.

I guess I can't accurately test the KM Engine until I remove all the Speak Text actions from my macros, which I use as debug statements.

If I recall correctly, you are on an iMac, no? Couldn’t you just switch the system’s audio output to the normal speakers, so that the Speak actions work also without any third-party stuff?


Now you have two possible ways to continue:

  • You take the results of your 20-minutes test as serious. That means, continuing your bug hunt under the assumption that a third-party factor is the trigger for the leak.

    • Of course, this makes the whole thing tedious, because isolating the responsible factor out of a few dozens of potential factors is not fun.
  • You try to solve the audio complications (either by eliminating the Speak actions or by making your audio work without third-party drivers), and continue with another extensive safe-mode test, hoping that you can reliably reproduce the memory issue also in safe mode.

    • This would be kind of a prove that the bug is a KM-“standalone” bug. Less work for you, more work for @peternlewis :wink:

BTW, it seems a bit odd to me that the absence of audio drivers produces such heavy issues (“Speak Text action is failing […] causing the entire Engine to hang up”). Maybe you should tell us more about your audio setup…

I had never considered that the debugger may be the cause of leaks in Normal Mode. That idea never entered my mind. I use the debugger frequently to debug. I'll have to pay more attention to that idea.

The speakers don't show up in the list (System Preferences, Sound, Output) when I'm in Safe Mode. The Apple TV does show up, along with what appears to be my HomePod speaker. The Apple TV is selected by default. I get an error after ten seconds when I try to connect to the HomePod but it still selects it.

So I'm not sure what you want me to do here.

I don't have any audio setup. All I have is the internal iMac speakers which disappeared when I booted in Safe Mode. As I said above, the Apple TV shows up as an audio option (it is selected in Safe Mode) and the HomePod appears to be there under the name "Dining Room" which likely means my HomePod.

I am pondering your two options for further investigation.

OK. A bit surprising that the iMac’s native audio software is disabled in safe mode. I have to check out on next occasion, if something similar happens with my MBP in safe mode.

So, personally I would go with Option 1 (taking the results of your 20-minutes safe-mode test as serious) and start to hunt for the culprit.

But I will not recommend this to you, because if after 5 days of trying to isolate the culprit you do another safe-mode test, and this time it turns out that you can reproduce the issue in safe mode, then… you will certainly kill me :wink:

However, if I recommend you to disable hundreds of Speak actions and continue the safe-mode test, and then it turns out that your 20-minutes test was right (= you cannot reproduce the issue in safe mode), then you will kill me also :wink:


PS:

Have you already tried out if the issue is still present in normal mode now?

(I’m asking because a safe boot also clears many caches, which can also be a factor.)

It's been only 20 minutes and I think I've replicated the problem in Safe Mode. I'm just creating a few macros as stubs to make my life easier in the future. And the memory is fast rising at a rate of about MB per second. It's up to 500 MB now. Here's an example of a stub macro:

For the most part I haven't even tested any of my stubs yet. The memory leak is just caused by using the KM Editor in Safe mode.

I'll continue to test but that's how it's looking at the moment. Once it hits a couple of Gig of RAM I'll repot back.

If you see any typos in my email that's because in Safe Mode the OS cannot keep up with my typing. Not my fault.

OK, sounds good.

Can you upload one of those “stubs”?

Ok sure. Sec...

You could also upload it here. No need to make a new topic.

1 Like

Yes, but I find the method for posting on existing threads confusing! I know it was explained to me but it's an unnatural method which I keep forgetting. I'll try again.

Just drag the macro into the editor field of the browser.

∆ Move Mouse to Absolute Position [x],[y]

Ok I just dragged a macro from KM Editor into this browser. I don't think it worked, let's see....

Sorry, an exported macro, I meant.

Export the macro to somewhere (e.g. Downloads folder) and drag it from the Finder.
“Export” is in KM Editor’s File menu.

Ok how about this. Seems to have worked.

∆ Move Mouse to Absolute Position [x],[y].kmmacros (2.1 KB)

Here's a larger stub.

∆ Type [key].kmmacros (31.2 KB)

Could you also upload the trigger macros? (The macros that pass the %TriggerValue%s)

I don't have any trigger macros. I haven't run anything yet. Well, sometimes to debug I might click on the Try button but for the most part I haven't even tested these macros yet.

Is this also the case in normal mode?