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 / AGK2 BASIC: Game's RAM keeps increasing

Author
Message
ABCProgrammer
9
Years of Service
User Offline
Joined: 21st Jul 2015
Location:
Posted: 21st Jul 2015 23:39 Edited at: 22nd Jul 2015 05:42
I want to write a little Pong game, but the RAM of the following game keeps increasing and slowing down the longer I run it.

Note, it's not completed yet, it has terrible design, etc.
I just want to know why the performance of the game get worse and worse the longer I run it.

I've also attached the following code as .agc file

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Jul 2015 00:05 Edited at: 22nd Jul 2015 00:06
The reason is because you createText() multiple times every loop, and never delete it. You are creating thousands of text objects as your game progresses.

You are using what I would describe as "old fashioned" game coding techniques. AppGameKit uses more sophisticated methods.

You are drawing boxes to the screen every loop. At the end of each loop these are destroyed and you draw them again.

In AppGameKit, you should create sprites. these can be images or simple box shapes. They do not get destroyed at the end of each loop. You create them once at the beginning, and then simply reposition them each loop.

Your text is this type of persistent object. You create it once and it remains forever, or until you DeleteText(). This is why you are creating thousands of text objects and the memory usage is increasing.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
MikeHart
AGK Bronze Backer
21
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 22nd Jul 2015 00:06
You create new text objects in CreateBoxes at every frame.

-----------------------------------------------------------
Using AGK2 Tier 1
ABCProgrammer
9
Years of Service
User Offline
Joined: 21st Jul 2015
Location:
Posted: 22nd Jul 2015 05:40
Ahh, Thank You. I expected them to delete themselves when I first created them. Well, I won't repeat that mistake again so easily.

Login to post a reply

Server time is: 2024-11-25 21:38:31
Your offset time is: 2024-11-25 21:38:31