iOS icon indicating copy to clipboard operation
iOS copied to clipboard

Memory leak

Open jedisct1 opened this issue 2 years ago • 75 comments

Device model, version and app version

Model Name: Macbook Pro with M1 Max, macOS Version: MacOS 12.3 App Version: Home Assistant Companion 2022.3 (2022.358) Safari Version: Version 15.4 (17613.1.17.1.6)

Home Assistant Core Version

2022.3.5

Describe the bug

Looks like there's a memory leak.

I've been running the companion app in the background for a few days and the system eventually ran out of memory:

Screen Shot 2022-03-17 at 21 17 01

To Reproduce

Expected behavior

Screenshots

See above.

Additional context

jedisct1 avatar Mar 17 '22 21:03 jedisct1

+1

mrwogu avatar Mar 18 '22 22:03 mrwogu

+1 Been happening for me since January

poster983 avatar Apr 07 '22 17:04 poster983

+1 I have this issue ever since I got the M1 MacBook Pro. The amount of memory allocated by Home Assistant app is insane, Mac's temperature is rising and then there is the battery drain issue.

uninstalled and reinstalled the app with no luck.

manosioa avatar Apr 11 '22 14:04 manosioa

I also have the M1Pro Mac Book Pro so it could be an issue with Rosetta 2?

poster983 avatar Apr 11 '22 22:04 poster983

The app does not use Rosetta.

Very likely this is an Apple bug in Catalyst apps, but it can be helpful to narrow down what's taking up memory space. You can help debug this by doing a few things when this occurs:

  1. In Activity Monitor, double-click Home Assistant and run "Sample" on it.
  2. On the command line, run leaks <pid> (where is the "process group" number in Activity Monitor)
  3. On the command line, run heap <pid> (same as previous)

Save these files off and attach the text files here.

zacwest avatar Apr 11 '22 23:04 zacwest

Hey @zacwest

Here are my findings as soon as the app was acting out again

Home Assistant Heaps.txt Home Assistant Leaks.txt Sample of Home Assistant.txt

Screenshot 2022-04-13 at 09 55 47 Screenshot 2022-04-13 at 09 55 29

manosioa avatar Apr 13 '22 07:04 manosioa

Thanks @manosioa. Of course the moment I need it to start leaking it doesn't for days

poster983 avatar Apr 13 '22 15:04 poster983

Happening here as well. Reaches up as much as 55gb. Restarted the app and it immediately went up to 8gb memory usage.

Sample of Home Assistant.txt Home Assistant Heaps.txt Home Assistant Leaks.txt

gthrift avatar Apr 13 '22 17:04 gthrift

Finally.. Here are mine HAHeaps.txt HALeaks.txt Sample of Home Assistant.txt

poster983 avatar Apr 15 '22 13:04 poster983

Screen Shot 2022-04-15 at 10 17 49 AM

brianegge avatar Apr 16 '22 16:04 brianegge

After ~4 hours. Also am on M1 (Max). leak@2x

adamfeldman avatar Apr 29 '22 15:04 adamfeldman

Thanks for all the logs. I have an idea what may be the cause. Do you all have a lot of entities? I think it may be the app keeping track of states - storing a small part of a state change is keeping the entire API response in memory, which means it'll scale fast if you have many frequent state changes.

zacwest avatar Apr 29 '22 19:04 zacwest

I do have a lot of entities. I have a script that essentially starts a “Disco Mode” which very quickly updates all my lights (~50) to random colors. It would always crash the iOS app. So I’ll test this with the macOS app when I get home today.

poster983 avatar Apr 29 '22 20:04 poster983

I too have a lot of entities. The weird thing is that it can run smoothly for an extended period of time and suddenly starts acting up.

manosioa avatar Apr 29 '22 20:04 manosioa

Yes, I have a lot of entities.

On Fri, Apr 29, 2022 at 3:56 PM Zac West @.***> wrote:

Thanks for all the logs. I have an idea what may be the cause. Do you all have a lot of entities? I think it may be the app keeping track of states - storing a small part of a state change is keeping the entire API response in memory, which means it'll scale fast if you have many frequent state changes.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/iOS/issues/2101#issuecomment-1113671209, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABB6R6CQ2GFEOQ4MJPSD4KDVHQ5GVANCNFSM5RABXPZQ . You are receiving this because you commented.Message ID: @.***>

gthrift avatar Apr 29 '22 20:04 gthrift

Same.. lots of entities (about 500) and not only is there an issue with memory I have high cpu usage as well. On both the macOS app and systemstats service.

Not sure why it needs to pull all the entities especially when the app is running in the background. I just need it to send some sensor info to home assistant (if my laptop is running, display connected as well etc).

skynet01 avatar May 12 '22 23:05 skynet01

Hi!

Any news regarding this? Still having big issues with the App

manosioa avatar May 19 '22 06:05 manosioa

MacBook 13" M1 - macOS 13 dev beta 3 It's started to leak more often compared to macOS 12.

Zylvo avatar Jul 12 '22 11:07 Zylvo

Can confirm this issue still happens, might be related to putting macOS to sleep mode often, instead of properly shutting down the computer?

HeySora avatar Aug 02 '22 21:08 HeySora

I guess you don't own either a Mac or a modern laptop. You don't have to shutdown the computer. Just closing the lid or in case of an iMac just walking away does the trick. The app should work correctly.

manosioa avatar Aug 02 '22 21:08 manosioa

I guess you don't own either a Mac or a modern laptop. You don't have to shutdown the computer. Just closing the lid or in case of an iMac just walking away does the trick. The app should work correctly.

@manosioa I do own a M1 Pro MacBook Pro, I am affected by this issue (I said so, "Can confirm this issue still happens"...)

I am just the kind of person closing my Mac's lid all the time, my current uptime is near one month.
Since solely using sleep mode is something that I reckon not everyone does, I am not saying using sleep mode is wrong, I tried assisting this issue's resolution by hinting "maybe this is related to sleep mode?" which is something that is commonly overlooked in desktop applications.

Of course the app should work correctly, but not every app does, and maybe it is the issue of this specific memory leak.

HeySora avatar Aug 03 '22 15:08 HeySora

+1

d4wud avatar Aug 10 '22 20:08 d4wud

Piling on to say this happened to me; within a few days of installing the app (2022.387) my 14" MacBook Pro (M1 Pro, 16GB) ground to a halt and completely died after throwing up the "out of memory" screen. Home Assistant was using just shy of 60GB. As far as my usage pattern, my MacBook stays plugged in at my desk pretty much all the time and goes to sleep when idle.

I saw a theory above that this may be exacerbated by having lots of entities....and I have a lot of entities (don't know how many exactly, but many many hundreds, probably around 1000).

rogersmj avatar Aug 25 '22 15:08 rogersmj

image Also seeing the same on M1 Max. I will say the worst part of this is seemingly the only way to recover is to reboot the machine. Definitely on a high number of entities like the rest of the thread.

qbunt avatar Sep 02 '22 15:09 qbunt

Can't you just kill the HA process without having to reboot? Also I think you are the top winner for the most ram usage screenshot. Let's see if anyone can beat it!

skynet01 avatar Sep 02 '22 20:09 skynet01

@skynet01 I don't think Activity Monitor catches everything it should and the system feels really sluggish until a reboot. It's super odd, I'm not going to use it on my daily driver until this is fixed, it's kind of dangerous.

qbunt avatar Nov 22 '22 22:11 qbunt

Got the same, seems to happen when it loses connection to HA.

TychoWerner avatar Nov 29 '22 10:11 TychoWerner

Hi al, I have the same issue

image

Apple M1 Pro - MacOS 13.0 (22A380)

johandijkstra avatar Jan 02 '23 13:01 johandijkstra

Interesting my Force Quit menu doesn't show any memory sizes. Sounds like this problem is only happening on M1 / M2 Macs? My Activity Monitory shows HA is only using 43 MB. (my Mac has an Intel i7)

Screen Shot 2023-01-02 at 16 07 23

progrmr avatar Jan 03 '23 00:01 progrmr

Maybe this needs some attention now that Reddit has taken notice. Does this need more diagnosis?

qbunt avatar Mar 01 '23 20:03 qbunt