Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / AGK - Memory Leak? Apps keep increasing memory usage....

Author
Message
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 5th Jul 2018 17:22 Edited at: 5th Jul 2018 18:50
I'd be interested to hear if others are getting this... If I start a brand new project and simply run the default starting app (Code below)



It gradually uses more and more memory. Just done a test and so far....

Launched just after lunch at 13:15 - Went from 19.6Mb to 22.4Mb fairly rapidly (but perhaps this is just task manager catching up?)
Then...

At 13:16 = 22.4Mb
At 14:19 = 30.9Mb
At 15:37 = 31.9Mb
At 16:30 = 32.4Mb
At 17:22 = 32.8Mb
At 18:42 = 33.4Mb

This is on a machine that is not being touched. Windows 10 and default programme compiled under latest build of AGK. Tier 1. Surely this shouldn't be happening?!
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 5th Jul 2018 19:06
I'm stopping it now, At 19:04 = 33.6Mb

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
puzzler2018
User Banned
Posted: 5th Jul 2018 19:43
ok - ill check mine soon - just busy with other stuff at mo
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 5th Jul 2018 20:13
Cool, thanks.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jul 2018 20:15
Ran the code and checked all 4 memory stats (Commited, working, Shareable, Private). They stayed 100% constant.

Do you have plenty of memory? Is your PC having to page memory to disk? Are you sharing memory with your graphics card?
Something else could be releasing memory that allows AppGameKit to take more.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 5th Jul 2018 21:21
Oh, not what I was expecting!

It's a highly spec'd PC - 64Gb Ram so paging shouldn't be happening. Guessing I'm not sharing memory with graphics card (it's a beefy GFX card too - GeForce GTX1080) but not sure how to check this.

Very odd - what else might be causing it?!? Anti-virus?
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 5th Jul 2018 21:44
I'm was looking at the Task Manager - Processes Tab - Memory Column for the app and that's the memory figure that's increasing. Just been into the Details tab and added the columns you refer to and I can see an increase across all of them - albeit a very low one for the Memory(Shared Working Set)

I'm using a modern PC that's pretty clean so baffled how i can be seeing the increase whilst you're not. That said I did think it would be odd that no one else had noticed it! How long did you leave it for?
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jul 2018 08:09
I left it for 10 minutes, and I didn't even get a shift of 1KB.
I've started it again for a longer test this morning, and oddly it is varying slightly. I'll report back later.

It's amazing what you see when you're looking for details. I just noticed that my frame rate is a constant 29.999784 for a couple of seconds. Then it drops around 300 microseconds, and ramps back up to the same constant speed again. Repeat, repeat...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 6th Jul 2018 08:22
I've just tried it on another machine (older Win 7 PC but again with 64Gb of Ram - I do 3D hence the large ram in my PCs) and that one also creeps up its memory usage.

If you can leave the programme running for an hour or two that would be great. Look forward to hearing your report!

Anyone else want to give it a go? I'd really like to see a few people try - as I can't be the only one seeing this and I'm keen to know if it's an AppGameKit issue or a feature of windows (I read somewhere that Windows considers unused ram as "wasted" ram and offers more and more ram to applications and only takes it away again if another process requires it) or something else...

Default programme... compile... run... record ram usage... wait an hour or two ... record ram usage and post!
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jul 2018 08:50 Edited at: 6th Jul 2018 08:51
The results are in and you are going to be surprised, figures are start and 40 minutes later...

Commit : 64140 => 63094
Working: 94552 => 48964
Shareable: 43912 => 43956
Private: 50744 => 5008 (not a typo!)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 6th Jul 2018 09:02
This just makes no sense?!?!?!

I do wonder... I left my application running with nothing else running (apart from the million background processes windows starts)... so did windows just give it more ram. Wondering if you had other applications running on the machine and windows decided to remove some ram fro the tiny AppGameKit one to help other applications? My 64Gb of ram is pretty overkill in most scenarios (except 3D!!) and especially to run the default AppGameKit programme(!!!) so wondering if windows is being super-generous in it's allocation? I used to think that applications required XMb to run and they just stuck to that (unless they had a leak)... I'm beginning to wonder.

How much ram does your PC have and were you running other applications during the test?


Really keen to see what others are getting too.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 6th Jul 2018 10:35
This could be the garbage collector. Don't know for sure, one of the developers will need to verify. I don't know how AGK's GC works, but this explanation is based on my experiences with other garbage collectors. When an object is created, AppGameKit will reserve some memory for it. When that object is no longer needed, it isn't removed from memory right away, but simply marked for cleanup. After some predetermined formula, the GC will finally remove the object, usually based on what the program is doing, ratio of objects still in use vs those waiting to be cleaned, or some kind of memory threshold. Usually the formula will settle on a point between performance and memory usage. It is not unusual to see a program's memory, written in a memory managed language, go up and down several times before settling on a happy medium.

Now you might think the code above shouldn't have that problem as you are not creating sprites, loading images, creating memblocks, etc... However, you are creating objects without realizing it. ScreenFPS creates a string object that is copied when returned, then passed to the Print function which creates its own copy. The runtime probably creates objects as it takes the string and converts it into a pixel format that can be displayed on the screen. All this is happening inside a tight loop.

10-20 megabytes is not that much for the GC to hold on to, especially on a machine with 64GB of memory. Try running your app for a while, see if memory usage increases past 100MB (indicating a leak very likely) or if memory usage finally settles down around a single value, or even drops a bit.
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 6th Jul 2018 10:43
Ok, just ran the above for about 10 minutes (all I have time for now) on a 4GB system. Memory usage as reported by task manager climbed to 43.2 MB, then dropped to 43.1 MB, where it settled and remained steady. This would indicate that it is just GC behavior and not a memory leak.
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 6th Jul 2018 11:40
OK, that's interesting. This sounds similar to the article I briefly skimmed about memory being used. Thanks also for your comment in my original thread.

The issue it leaves me with is that I think I've been a good boy and cleaned up all the items I create (I can see sprites managed remains consistent and image memory remains consistent but can't see things like arrays being created or text being created - tough that too I can monitor thanks to BatVink's idea) but without a constant memory usage I don't know if I've got a leaky program or whether it's GC or anything else outside of my control... I guess the ultimate test is to play the game for a number of hours and see if the increase is large enough to cause an issue. I think my platform game uses around 80Mb or ram so I'm guessing it's just not going to be an issue even if it does go up a fair amount because of GC or the way windows manages memory (which really is outside of my control!)
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 6th Jul 2018 12:05
I wonder if some extra bench-marking commands might be useful - to report on array memory, text objects held in memory, sounds held in memory.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 6th Jul 2018 17:38
In modern times these are really, really low numbers.....not even a phone would struggle here. I think the rule is modern operating systems handle all the background stuff, especially phones, so unless you're massively overloading it why worry?
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 6th Jul 2018 18:42
You’re probably right!
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jul 2018 00:29 Edited at: 8th Jul 2018 02:17
I ran your example and mine also steadily increases, starting at 18.5MB and reaching 24.8MB after about a minute. I have 32GB ram so nothing should be paged. After a few minutes I'm now at 28.9. I'll let this run for an hour just to see what happens.


For those saying it's too little memory to even worry about, that's not the point. If there is a memory leak, no matter how small, it needs fixed.

It's now at 30.2MB after almost 2 hours
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jul 2018 11:27
Woke up this morning and it was back down to 18.5MB
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 8th Jul 2018 11:44
No one is saying it's too little to worry about. We're saying that a small increase in memory usage is normal in a memory managed language and not necessarily a memory leak. If the memory increase continues over a large amount of time and accumulates into a large value, then you can start worrying about memory leaks. What would constitute as a large value would depend on the implementation of the GC, The amount of memory you have, the version of windows, how many programs are running at the same time, etc...

Just started the test program, and memory shot up to 43.9 right away. Then it dropped to 43.8. It seems to jump back-and-forth between 43.9 and 43.8. I am testing on a 4GB machine. It would not surprise me if the GC grabs a larger chunk of memory right off on lower memory machines to prevent the likelihood of paging, and then kick in sooner to keep memory free. AS I stated previously, this would need to be verified by one of the developers.

Just a little aside, the first time I had to deal with a garbage collector was with Commodore 64 BASIC. More memory was used every time a new string was created, concatenated, truncated, or otherwise manipulated. The memory wasn't freed until it was all filled. If you had a BASIC program that used a lot of string manipulations, you would have the program suddenly freeze for half a minute while it would free memory and move all the strings together to make room. If you checked for free memory with the FRE(0) command, then the GC would be called to free up memory so that an accurate total could be returned. So to prevent these freezes, you would often put FRE(0) in places where the freezing would be less noticeable, such as when switching to the main menu, and will take less time as there is less to collect.

Note: as I typed this, the program has been running for about 15 minutes. Memory usage is still toggling between 43.8 and 43.9 MB
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 8th Jul 2018 12:18
Ok, been running for a little more than 45 minutes. Memory climbed to about 51.2 MB. Went to take a shower, and when I came back, the memory has dropped to 5.4 MB. I'm convinced this is merely normal GC behavior and not any kind of memory leak.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Jul 2018 12:53
Considering I ran mine for about 12 hours and it seemed to stabilize and even drop back down, I'd say there's nothing to worry about. Unlike chrome which climbed up to 11GB and 80% CPU.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 9th Jul 2018 20:54
Wow - that's not good re Chrome!

Thanks guys for looking into this and giving feedback - appreciate it. Always learn something when I come onto these forums!
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)

Login to post a reply

Server time is: 2024-11-23 17:48:16
Your offset time is: 2024-11-23 17:48:16