November 15, 2019, 09:01:39 AM

Author Topic: Memory accmulation problem in blitzmax  (Read 248 times)

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 298
Memory accmulation problem in blitzmax
« on: October 24, 2019, 05:25:27 PM »
Hi.. I have a problem which i find hard to solve..

When I delete Elements In My Game Editor On Edit mode the memory gets free.
But when I press play game and than the Game Delets an Element.. it doesnt get removed from the memory.. (there is no Compilation process Involved..)

Ive tried to trace this memory accumulation and compare it to the state where the Engine is on Edit mode..
and I could not find any difference..

I break my head for days trying to solve this problem but I cant..

its not a GCcollection issue.. as far as i can tell.

Any Ideas?

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1009
Re: Memory accmulation problem in blitzmax
« Reply #1 on: October 24, 2019, 05:39:31 PM »
what kind of assets (loaded or made in code) do you use ? maybe you can get an idea of the cause of the accumulation by calculating the approximate size (in bytes/octets) that each asset takes in memory, when created / added to the scene...

when i make a tool / game, it is a combination of separate templates / procedures / systems, so if i don't know where a an error / bug comes from, i just have to start from scratch and assembles the templates / procedures / systems again (but first i make sure that each one works well and has no bug and is stable, individually...)

(this approach helped me to identify several (only a few really) bug caused by Blitz3d, internaly, not by me)
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Derron

  • Hero Member
  • *****
  • Posts: 2569
Re: Memory accmulation problem in blitzmax
« Reply #2 on: October 24, 2019, 05:46:59 PM »
If your editor still holds the reference to an object it cannot get deleted.

editor -> selectedObject:object = "object #123"
game -> oneOfTheEnemies:object = "object #123"

if you now do a "game.oneOfTheEnemies = null" it will not be collected as "editor.selectedObject" is still referencing it.

Such references might also happen indirectly
editor -> entities -> ["object #1", "object #2", ..., "object #123"]
or in a TList, TMap, ...



bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 298
Re: Memory accmulation problem in blitzmax
« Reply #3 on: October 24, 2019, 05:53:13 PM »
Eventually I will catch this error.. since like i said I dont do anything different other than a Flag that tells the Engine its on Game Mode..
So.. thanks for the advises..  it was worth asking.

Im working on an elimination method.. until ill catch that thing that is responsible.

Elimination is one of the best methods to trace a problem..

Offline TomToad

  • Sr. Member
  • ****
  • Posts: 451
Re: Memory accmulation problem in blitzmax
« Reply #4 on: October 24, 2019, 05:56:03 PM »
Memory is not freed immediately after an object is deleted. The garbage collector decides the best time to remove objects so performance is affected as little as possible. It is normal for memory usage to steadily increase, but it should taper off and remain constant after a while.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 298
Re: Memory accmulation problem in blitzmax
« Reply #5 on: October 24, 2019, 05:59:05 PM »
What Im facing is a difference between two almost identical states.. that why I know its not what you Just Said.. But Thanks for that info. Its helpful..

BTW,Does the GCcollect On by default ?

10 mins later..
----------------
Ok, Ive managed to narrow the problem, but yet not catch it.
This is a big progress..

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 298
Re: Memory accmulation problem in blitzmax
« Reply #6 on: October 29, 2019, 10:27:58 PM »
It took me one week.. but I solved the memory error...

I did a counter on my Type Creation and when I deleted the Type the counter was reduced by one..
By comparing the numbers I could have see if the amount of this Type that was created is equal to the amount of this Type that was deleted..
this helped tracing the leak..

this was very frustrating long process.. but thats programming

Offline Derron

  • Hero Member
  • *****
  • Posts: 2569
Re: Memory accmulation problem in blitzmax
« Reply #7 on: October 30, 2019, 07:40:22 AM »
so ... where was the leak now?


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 298
Re: Memory accmulation problem in blitzmax
« Reply #8 on: October 30, 2019, 08:12:09 AM »
When i did stop playing map in my editor
It did "listremove" to an object that wasn't yet deleted..

When the deletion process came, it did not delete that object because it was not on the list

Offline Derron

  • Hero Member
  • *****
  • Posts: 2569
Re: Memory accmulation problem in blitzmax
« Reply #9 on: October 30, 2019, 08:36:21 AM »
So you only proceeded deletion when it was in the "managed list" ?
Take care of the "WHY" you planned it that way - to avoid having fixed something now but creating a behaviour change on another part of the code.


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 298
Re: Memory accmulation problem in blitzmax
« Reply #10 on: October 30, 2019, 09:24:01 AM »
Hi Derron.

This is a game Editor. When I press play the objects like spaceships should exist. when I press stop play the objects should be deleted..
they cant be deleted just for no reason.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2569
Re: Memory accmulation problem in blitzmax
« Reply #11 on: October 30, 2019, 10:20:53 AM »
They can be deleted if there is no longer any use for them.


As I read your posts it sounds as if you deleted something from a list which was not prone to get deleted. This is OK ... and it would be purged from memory correctly - if there is nothing still referencing it.
So if you remove something from a list (and the list is your only reference to it) then make sure to inform that object about the deletion ... so it could remove any circular dependencies it might still have
(object1.children = object2... object2.parent = object1). Also it might be referenced by something else - leading to the effect of staying in memory (it is still in use!).

Yet deletion from a list - and potentially doing unreferencing/cleanup could lead to segfaults then - if something blindly accesses a property which was unset "remotely".


edit:
Your game editor ... can't it just have a reference to some "TGame" instance?
As the logic of the TGame-children-management is hardcoded you can just manage the TGame-children from within that TGame. The editor just emits commands ("TGame.AddChildren(...)").
The "TGame" does not need any information of "TEditor" - so every manipulation started from "TEditor" directly affects "TGame".

Exception is stuff you want to setup but not attach to the game yet - like "templates" or so. They are managed by the "TEditor" then (and there is no reference from "TGame").


I do not want to say you are doing things wrong - nor that my idea of doing stuff is better than others. Just want to make you think about the way you approach stuff - maybe there is a little issue somewhere leading to problems sooner or later.



bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 298
Re: Memory accmulation problem in blitzmax
« Reply #12 on: October 30, 2019, 12:39:37 PM »
Hi.
I have certainly did many things wrong.
I jumped into a very deep pool with no experience.
I didn't know there is a TGame type.
I don't know many things apparently.

Each 3d object of mine is attached to a type.
When my editor went into stop mode,
Only the 3d objects were deleted but the attached type didn't..
Hence the memory accumulation.
Now it's solved, so for now it's no longer an issue..

I will share all my system idea soon
And im sure it can be improved by you expert guys.
For now im satisfied as it is.

Derron, I will read what you wrote again and try to understand it.
Im not that pro

Offline Derron

  • Hero Member
  • *****
  • Posts: 2569
Re: Memory accmulation problem in blitzmax
« Reply #13 on: October 30, 2019, 07:28:54 PM »
Ahh .. .so you had some kind of "ManagerObject" which had the "3d object" attached. Your editor had a list of " ManagerObjects". You then removed the "3d objects" from your "game" - but did not remove the "ManagerObject" having the "3d objects" attached.
Right?

Sounds like a simple and stupid mistake we all do sooner or later - glad you found it.


@ TGame
No it does not exist - I just thought you created such a thing :)


bye
Ron

Offline Hardcoal

  • Sr. Member
  • ****
  • Posts: 298
Re: Memory accmulation problem in blitzmax
« Reply #14 on: October 30, 2019, 07:45:32 PM »
Yeap thats exactly what it was.. :)