imxieyi / waifu2x-ios

iOS Core ML implementation of waifu2x
MIT License
538 stars 58 forks source link

MacOS Memory Leak? #45

Closed ArguingMeadows closed 2 years ago

ArguingMeadows commented 2 years ago

I keep running out of system memory since updating to Monterey 12.2.1 and Waifu2x 5.3.6 on my M1 Pro Macbook Pro with 16 GB of RAM and my Intel iMac with an Intel Core i9, Vega 48 GPU with 8 GB or HMB2 VRAM and 64 GB of RAM. I know Monterey has a memory leak issue that's been thrown around but it only happens to me using this specific app.

imxieyi commented 2 years ago

Can you provide a description of what you were doing? For example processing images or videos, model configurations, etc.

ArguingMeadows commented 2 years ago

I would try to upscale a video. I used to be able scale up to an hour-long video on any model with no problem. Now, the I'm lucky if I can upscale a video that is a little over a minute. Model doesn't seem to matter, it happens on both Real-ESRGAN and CUnet at the very least from my testing. Doesn't matter what type of video either. H.264, HEVC and ProRes export all cause the same issue.

ArguingMeadows commented 2 years ago

Update: Testing it on the SCRNN Illustration model, it did not result in a memory leak on a video just over 90 seconds long.

imxieyi commented 2 years ago

That's weird. I never had any issues regarding memory leak on any model. But I'm on 12.0.1. I'll update to the latest macOS to see if it happens to me as well.

ArguingMeadows commented 2 years ago

I think it’s more specifically Monterey 12.2.1 causing the issue since I didn’t have it before the update, but it is strange that this app is the only one that triggers it. Thank you for looking into this.

imxieyi commented 2 years ago

I updated to 12.2.1 and still didn't see any memory leaks in Xcode debugger. Then I noticed that in Activity Monitor the Real Mem was steadily growing while processing a video. It was not as bad as you described though. I tried to upscale a 90s video 1080p -> 4k with Real-ESRGAN and at the end it only grew to 2.70GB. A memory graph sample in Xcode didn't show anything leaking. And the memory usage reported by Xcode stayed at around 110MB during the whole process. I also tried to use Xcode profiler and still no luck.

It happens with SRCNN as well. It's just not leaking as fast.

I also tried CLI and unfortunately it had the exact same problem.

Therefore I believe it is an issue with macOS itself. The app already released its memory but for some reason the OS kept some of them unreleased. And existing tools provided by Xcode are not able to capture them. We may have to wait until the issue is fixed in macOS.

ArguingMeadows commented 2 years ago

I was starting to think it's Monterey as well, but I figured I'd mention it. Thank you for looking into this. I'll send feedback to Apple.

imxieyi commented 2 years ago

Today when I tested on my M1 MBA with a 90 sec video again the Real Mem behavior changed. It increased to 1.5GB during the first half of the process and stopped there. After the video processing was completed it quickly dropped to <100MB. Then I tried on my Intel Mac again with the exact same video and setup and unfortunately it still steadily increased to almost 3GB and didn't drop after the process was completed. Looks like this is a very janky issue that does not always reproduce.