Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak? #173

Closed
takuhii opened this issue Oct 4, 2016 · 27 comments
Closed

Memory Leak? #173

takuhii opened this issue Oct 4, 2016 · 27 comments
Labels

Comments

@takuhii
Copy link

takuhii commented Oct 4, 2016

No sure what's happening here, but I have Terminal Notifier running in 5 Terminal windows, but it is consuming GBs of memory, so much so my Macbook stops working...

screen shot 2016-10-04 at 13 18 10 2

@julienXX
Copy link
Owner

julienXX commented Oct 4, 2016

Which version do you use?

@takuhii
Copy link
Author

takuhii commented Oct 4, 2016

It updated over home brew this morning, but I believe it is version 1.7.0

@julienXX
Copy link
Owner

julienXX commented Oct 4, 2016

Could you try this version https://github.com/julienXX/terminal-notifier/releases/tag/1.7.1 and tell me if it's better? (Not yet available via homebrew)

@takuhii
Copy link
Author

takuhii commented Oct 4, 2016

ok, I'll give it a whirl and keep you posted

Thank you :)

@julienXX
Copy link
Owner

julienXX commented Oct 4, 2016

I managed to reproduce the issue when using -reply and no action is taken for example, this keeps terminal-notifier running and eating RAM.

@frdmn
Copy link

frdmn commented Oct 5, 2016

Same problem over here. 15 GB physical memory + 30 GB swap:

bildschirmfoto 2016-10-05 um 15 05 23

@julienXX
Copy link
Owner

julienXX commented Oct 5, 2016

@takuhii @frdmn what did you do with terminal-notifier in order to get this? Launch notifications manually, via a script... ?

@takuhii
Copy link
Author

takuhii commented Oct 5, 2016

You're 1.7.1 update did the trick @julienXX I've had no more "leaks". The only thing I had to do after I applied it was reboot my Mac... I am invoking Terminal Notifier via a Script BTW ;)

@julienXX
Copy link
Owner

julienXX commented Oct 5, 2016

@frdmn do you have the issue under 1.7.1?

@frdmn
Copy link

frdmn commented Oct 5, 2016

@julienXX I was using the homebrew / Ruby wrapper of the binary. How can I extract just the terminal-notifier binary out of this .app bundle?

When I just copy it from Contents/MacOS/terminal-notifier I get the following error message:

2016-10-05 15:52:58.476 terminal-notifier[18802:3271692] No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting

@julienXX
Copy link
Owner

julienXX commented Oct 5, 2016

@frdmn 1.7.1 is available via homebrew or you can download the executable here https://github.com/julienXX/terminal-notifier/releases/tag/1.7.1

@frdmn
Copy link

frdmn commented Oct 5, 2016

@julienXX Ah great, just got the update in brew. I'm not sure how to reproduce the problem precisely, but for now none of the processes are stuck and memory looks good as well. 👍

I'll let you know if the problem still occurs with 1.7.1

@julienXX
Copy link
Owner

julienXX commented Oct 5, 2016

Great, I close the issue, feel free to re-open it if needed.

@mikaelbr
Copy link

Could this still be a problem? https://github.com/swhamilton/jest-terminal-notifier-memory-leak

cc @swhamilton

@killianbrackey
Copy link

I am having the same issue that @mikaelbr is seeing using Jest with terminal-notifier 1.7.1 updated via homebrew.
Cloud app video of the the leak: https://cl.ly/1H2I2X1T123d

@alloy
Copy link
Collaborator

alloy commented Mar 11, 2017

@julienXX The original code was written with the idea that the app would always exit asap after delivery. I see that nowadays there’s the possibility for the app to remain running when waitForResponse is set and then checks if the notification is still present.

I don’t know how long it can remain ‘present’ nor have I done anything else than skim through the source, but it does look like that might be the source of the leak, as it continuously generates autoreleased strings which will never get released (until the app exits). I suggest you create the string with hash once outside of the while loop and keep an eye on other objects being created in situations where the app might be running for a long time.

@mikaelbr
Copy link

Shouldn't waitForResponse here respect the timeout?

@julienXX
Copy link
Owner

I don't yet have a fix but I'm working on it. The code for the reply option was merged from https://github.com/vjeantet/alerter and it seems the leak was already there.

@mikaelbr
Copy link

mikaelbr commented May 1, 2017

@julienXX Is this still being worked on?

@julienXX
Copy link
Owner

julienXX commented May 1, 2017

@mikaelbr yes it is but I'm having a hard time figuring out the proper fix.

@mikaelbr
Copy link

mikaelbr commented May 1, 2017

I see. I don't have any ObjC experience, so not much help there I'm afraid. But looks to me like the main source is the endless loop as alloy suggests. Also, are we sure checking in deliveredNotifications is the way to do it? Is that also a list of all notifications found in the notification list (not only as active notification?). In that case it would essentially be running forever. Which I think gives little value?

As for optimizing the loop it self, it looks like the entire

[NSString stringWithFormat:@"%ld", self.hash]

can be moved to above the do-while, also as @alloy says.

Looks like maybe the current code is from http://stackoverflow.com/questions/21110714/mac-os-x-nsusernotificationcenter-notification-get-dismiss-event-callback but there another identifier is used.

@alloy
Copy link
Collaborator

alloy commented May 1, 2017

@julienXX If you have any questions or want to pair, let me know.

@julienXX
Copy link
Owner

julienXX commented May 1, 2017

Thanks @mikaelbr and @alloy! I already moved the NSString above the do, tried to alloc and initWithFormat to avoid using an autoreleased object but that's not enough. I reduces the leak a bit it seems but it's still there.

@julienXX
Copy link
Owner

julienXX commented May 1, 2017

@mikaelbr @alloy tried some updates https://gist.github.com/julienXX/bb076b0b95c738217b03e14e51f23876 but still no luck. Leaking is reduced but still there. If you have some ideas to try I'm all ears.

@mikaelbr
Copy link

mikaelbr commented May 1, 2017

Could you reuse declared arrays and other values for each iteration of the loop? Now you allocate a new array in the memory for each step, no?

@julienXX
Copy link
Owner

julienXX commented May 1, 2017

@mikaelbr updated the gist but not better unless I misunderstood your comment.

@julienXX
Copy link
Owner

@mikaelbr @killianbrackey @frdmn @takuhii the leak has been found and fixed thanks to @alloy help. I released 1.7.2 with the fix. Soon available via homebrew too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants