Memory accmulation problem in blitzmax

Started by Hardcoal, October 24, 2019, 17:25:27

Previous topic - Next topic

Hardcoal

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?
Code

RemiD

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)

Derron

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

Hardcoal

#3
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..
Code

TomToad

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.

Hardcoal

#5
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..
Code

Hardcoal

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
Code

Derron


Hardcoal

#8
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
Code

Derron

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

Hardcoal

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.
Code

Derron

#11
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

Hardcoal

#12
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
Code

Derron

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

Hardcoal

Code