Jump to content

Character Controller Walking on Terrain=Memory Leak


Haydenmango
 Share

Recommended Posts

When I walk on terrain with a Character Controller my memory usage consistently goes up.

I tested this by using the Terrain map in the MyGame project with a Character Controller using the FPSplayer.script. I also put a check for memory usage and collectgarbage() in my main App Loop.

 

Further details can be found in the video I made--

 

https://www.youtube.com/watch?v=Bj0brR8_7eQ&feature=youtu.be

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

Link to comment
Share on other sites

Yes I recall reading that.

The memory never gets cleaned up. I've waited a lonnnnnggggg time and it will never go down.

By placing collectgarbage() in my main App loop I believe that stops lua from building up memory.

 

If your memory usage continually goes up, even if you call collect(), you probably have a leak.

 

Just don't use that in your normal code. Lua is meant to build memory up and then automatically release it periodically.
--Josh

 

Edit--- After testing more I found that when using the same setup but with a csg box instead of terrain the memory usage reaches a limit. Also when using just a camera to move around the memory usage increases if I have a terrain but the memory usage reaches a limit if it is a csg box.

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

Link to comment
Share on other sites

I guess, this could be because, as you move, more parts of the terrain have to be loaded into memory, so maybe some parts that are not visible in the beginning might get into view and have to be loaded into memory (just guessing here, I have no idea, how the terrain is implemented) and maybe the parts don't get released afterwards since keeping them in memory is cheaper than extracting them all over again (still guessing wink.png). I will test tomorrow, if I can confirm the memory-increase on my machine (with standalone version) as well, but if it is as I guessed, this would be a normal behaviour.

P.S.:

Did I mention, I was only guessing?^^

  • Upvote 1
Link to comment
Share on other sites

Yeah that seems like a reasonable cause for the 'issue'.

I was starting to come to a similar conclusion myself but you put it into words perfectly. That would be cool if you could do a test, let me know about the results!

 

The terrain in my test map didn't have any textures on it. So I am now wondering if having multiple terrain texture layers could increase the amount of memory allocated... I am guessing yes but then again I am only guessing at this point....

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

Link to comment
Share on other sites

You could make some character automatically running between two points and see how memory increases and see if it reaches a limit or not

Yes I have done this and it does reach a limit.

 

In theory you could make a character run around the entire terrain and the memory will reach a limit once you have been everywhere. I haven't tested that because it would take forever but I have tested it on a small csg box and after I ran around the entire box the memory usage did reach a limit and I could continue running without the memory increasing.

 

This probably isn't a bug then but it is kind of limiting and makes memory usage testing quite difficult.

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

Link to comment
Share on other sites

I just tested this and saw, it happened for me as well. Memory keeps increasing for terrain and for csg-box. I didn't wait to see, if there was a limit. I also noticed, this happens, if you just stand at one position and keep jumping (but not, if you don't do anything). Using self.context:DrawStats with the third parameter set to true, you also see the memory usage split into "script memory usage" and just "memory usage", where the latter one is the one, which keeps increasing, so it doesn't seem to be related to that particular script.

Link to comment
Share on other sites

At least it isn't just me. Thanks for testing that out.

 

Using self.context:DrawStats with the third parameter set to true, you also see the memory usage split into "script memory usage" and just "memory usage"
!!!!!!!!!!!!!!! I didn't know you could even do that! That changes everything!

I also noticed that just the memory usage rises for me too while the script memory usage stays the same.

 

edit-- What do "batches" stand for?

I get 6 batches when using my basic testing map but when I use my Hunt for Food map I get anywhere from 50-100ish batches which I am guessing isn't good. haha

  • Upvote 1

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

Link to comment
Share on other sites

I can't produce any leak. Sometimes there are structures in the terrain class that don't get initialized until they come into view, so if you are traveling around the memory may go up a slight bit. However, I don't see anything that looks like runaway memory allocation when I call collectgarbage(collect) each frame.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Ok well I have just been using collectgarbage() not collectgarbage(collect). Once I changed that I think I started getting more accurate results. It is good to know that some of the small memory bumps are possibly structures in the terrain class getting initialized and it is not a leak.

 

P.S. Knowing about the third parameter for DrawStats() is really helping me test my other projects! Also, I couldn't find the DrawStats() function in the documentation; did I miss it or is it yet to be created?

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

Link to comment
Share on other sites

What is the difference between "collectgarbage(collect)" and just "collectgarbage()"? In C++ there is not even an overload of that function that takes a parameter and it isn't documented.

 

P.S. Knowing about the third parameter for DrawStats() is really helping me test my other projects! Also, I couldn't find the DrawStats() function in the documentation; did I miss it or is it yet to be created?

 

You are right, it isn't documented. I found out about it because I usually use C++ for my projects and VisualStudio has the nice Intelli-Sense where it told me, there was a third parameter called "extra" that defaulted to "false".

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...