It is currently March 28th, 2024, 6:37 pm

[Fixed] Memory Leak?

Report bugs with the Rainmeter application and suggest features.
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

[Fixed] Memory Leak?

Post by Yincognito »

Hopefully I'm not right on this one as this would mean I'm bringing yet another bug report for you guys, but this is what I experienced when trying to answer a post regarding sliding meters on the forum...

Test skin:

Code: Select all

[Rainmeter]
Update=#Update#
BackgroundMode=2
SolidColor=0, 0, 255,100

[StyleItem]
X=0R
W=500
FontColor=255, 255, 255,255
FontFace=Arial
FontSize=12
StringEffect=Shadow
StringStyle=Bold
StringAlign=Left
AntiAlias=1
ClipString=1
Text="[\9654] %1"

[Variables]
Update=25
OriginalX=#SCREENAREAWIDTH#
TotalMove=2500
Y1=0

[MeasureRSS]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL="https://news.google.com/rss"
RegExp="(?siU).*<item.*>.*<title>(.*)</title>.*<title>(.*)</title>.*<title>(.*)</title>.*<title>(.*)</title>.*<title>(.*)</title>.*"
UpdateRate=20000
StringIndex=1
Debug=0

[MeasureMove]
Measure=Calc
Formula=Counter%#TotalMove#
AverageSize=1

[NewPosition]
Measure=Calc
Formula=#OriginalX#-MeasureMove

[MeasureRSSItem1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureRSS]
StringIndex=1

[MeasureRSSItem2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureRSS]
StringIndex=2

[MeasureRSSItem3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureRSS]
StringIndex=3

[MeasureRSSItem4]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureRSS]
StringIndex=4

[MeasureRSSItem5]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureRSS]
StringIndex=5

[MeterRSSItem1]
Meter=String
MeasureName=MeasureRSSItem1
MeterStyle=StyleItem
X=[NewPosition]
DynamicVariables=1

[MeterRSSItem2]
Meter=String
MeasureName=MeasureRSSItem2
MeterStyle=StyleItem

[MeterRSSItem3]
Meter=String
MeasureName=MeasureRSSItem3
MeterStyle=StyleItem

[MeterRSSItem4]
Meter=String
MeasureName=MeasureRSSItem4
MeterStyle=StyleItem

[MeterRSSItem5]
Meter=String
MeasureName=MeasureRSSItem5
MeterStyle=StyleItem

[MeterRSSItem12]
Meter=String
MeasureName=MeasureRSSItem1
X=([MeterRSSItem1:X]-#TotalMove#)
MeterStyle=StyleItem
DynamicVariables=1

[MeterRSSItem22]
Meter=String
MeasureName=MeasureRSSItem2
MeterStyle=StyleItem

[MeterRSSItem32]
Meter=String
MeasureName=MeasureRSSItem3
MeterStyle=StyleItem

[MeterRSSItem42]
Meter=String
MeasureName=MeasureRSSItem4
MeterStyle=StyleItem

[MeterRSSItem52]
Meter=String
MeasureName=MeasureRSSItem5
MeterStyle=StyleItem
Result: Windows and Rainmeter crash on my 4 GB RAM laptop, with the message "Out of memory" (it happened 3 times for me).
Warning signs: Continuously increasing values of Commited Memory, visible in the Memory section of the Performance tab from Task Manager:
Rainmeter - Memory Leak.jpg
Workaround: add all the sliding meters to a Container meter.

Since in my skins I always use containers for the animations, I obviously didn't noticed this before. When working with the skin in that post (which didn't use containers), the issue became easily noticeable. I couldn't get a confirmation of the problem from someone else yet, but I believe the values of the memory info in Task Manager can be taken as clear indication that something is not right.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG] Memory Leak?

Post by jsmorley »

There is certainly something very, very wrong with how that code is behaving. I can confirm that it just keeps adding to Committed Memory, endlessly as far as I can tell.

1.jpg


I never "crashed" for me, as I have Windows managing my pagefile.sys file, and it just kept growing that as needed to keep total Swap memory from running out. I expect that if I allowed it to fill up my entire SSD C: drive, it would in fact crash, but I wasn't going to let it run that long.

2.jpg
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Memory Leak?

Post by Yincognito »

jsmorley wrote: July 10th, 2020, 11:05 pm There is certainly something very, very wrong with how that code is behaving. I can confirm that it just keeps adding to Committed Memory, endlessly as far as I can tell.


1.jpg



I never "crashed" for me, as I have Windows managing my page file, and it just kept growing that as needed to keep things going. I expect that if I allowed it to fill up my entire SSD C: drive, it would in fact crash, but I wasn't going to let it run that long.


2.jpg
Yeah, but I also have Windows managing my page file, so that's not an issue. I think the crashes happened for me as I have less RAM available (4 GB is a small amount these days) so a smaller paging file as well (around 700 MB).

EDIT: As I said, putting the sliding meters inside a Container solves the issue and the memory stays more or less constant after that (you can check my last posted code in the thread I mentioned above and see), but then, I don't think this should happen in the first place, thus my post here. Thanks for confirming this, by the way. :thumbup:
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG] Memory Leak?

Post by jsmorley »

Well, the long and the short of it is that this skin should not be constantly creating "committed" memory without releasing it. It's not that it is using a lot of Physical memory, the Private Working Set stayed pretty constant, but the behavior with Swap memory is certainly not good.
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Memory Leak?

Post by Yincognito »

jsmorley wrote: July 10th, 2020, 11:12 pm Well, the long and the short of it is that this skin should not be constantly creating "committed" memory without releasing it. It's not that it is using a lot of actual memory, the Private Bytes stayed pretty constant, but the behavior with Swap memory is certainly not good.
Yep, indeed. And that just blows my entire "RAM monitoring" approach in my own (and probably others') skins, as just the Private Bytes weren't enough for me to become aware that a crash is going to happen eventually (and unload the damn skin before it happens)... :???:
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG] Memory Leak?

Post by jsmorley »

Yincognito wrote: July 10th, 2020, 11:16 pm Yep, indeed. And that just blows my entire "RAM monitoring" approach in my own (and probably others') skins, as just the Private Bytes weren't enough for me to become aware that a crash is going to happen eventually (and unload the damn skin before it happens)... :???:
Yeah, I might have noticed if I had bothered to look at my tooltip on my system skin, but likely not...


3.jpg
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Memory Leak?

Post by Yincognito »

jsmorley wrote: July 10th, 2020, 11:19 pm Yeah, I might have noticed if I had bothered to look at my tooltip on my system skin, but likely not...



3.jpg
Yeah, well ... then what's the point having a skin loaded and monitoring stuff if you don't look at it? :lol:
It must be quite hard to hover over the skin with the mouse for us folks ... I mean, you have to move the mouse a lot, keep it steady, check the numbers, do some computing, and so on... :rofl:
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Memory Leak?

Post by Yincognito »

jsmorley wrote: July 10th, 2020, 11:19 pm Yeah, I might have noticed if I had bothered to look at my tooltip on my system skin, but likely not...



3.jpg
Yeah, my bad as well, as a recently introduced meter in my skin (i.e. used swap / total memory percent, that was already available in the skin's "tooltip" anyway, just not in the "main" skin, before) should have been enough to warn me of the issue:
Warning.jpg
I guess the meter was "too new" for me to get used to it, hence my lack of awareness. Plus, the usual habit of looking at the processes and CPU skins (and not at the memory one) when searching for potential problems... :uhuh:
User avatar
Brian
Developer
Posts: 2673
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: [BUG] Memory Leak?

Post by Brian »

Hmm. Good catch. This has been fixed for the next beta.

[Technical_Details]
Apparently, DirectX's newer "flip" swap effects do not play well with mixed presentation. They are supposed to perform better because you draw things directly on the backbuffer instead of the old bit block transfer method (bitblt in GDI). Since we still use GDI to "present" the drawn contents to the screen, the window handle gets lost when "flipping" the contents to the screen.

This detail was buried in the "remarks" section of Microsoft docs...and the wording is a little unclear (at least to me).
https://docs.microsoft.com/en-us/windows/win32/api/dxgi/ne-dxgi-dxgi_swap_effect#remarks (2nd to last paragraph)
[/Technical_Details]

-Brian
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG] Memory Leak?

Post by jsmorley »

The new beta is out. This issue was introduced in r3373 a couple of weeks ago, so it hasn't been around long...
Post Reply