generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Preventing memory leaks on the client

Previous Thread :: Next Thread 
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
25 Oct 2016 06:34 PM
tl;dr: This lib helps combat memory leakage by storing client-created instances that are no longer used in an invisible buffer for later usage. It also automatically fetches all children of the instance when consuming it, too.

You may not know this, but often, destroyed instances don't actually get taken out of memory, even if no references are left to them in a script. Because of this, I've been set back by OutOfMemoryExceptions and such in demos/prototypes that I've produced. However, over the last night or so, I've managed to come up with a solution. I created a recycler class that stores returned instances in a buffer for later usage.

If none of a requested instance is present in a given buffer, it automatically allocates a new instance with your old Instance.new(). It's also semi-recursive in the way that it'll remove and recover _all_ of the children in a returned instance.

You can access ReCycle's BroadBuffer class by requiring the Utilities modulescript included in the model. It returns a table that contains the class itself. Once you have the actual class in a variable, say, 'Buffer', you can do something of this fashion:

NewBuffer = Buffer()

You can take instances out of NewBuffer like this (remember, they're dynamically allocated if you don't have one in the buffer):

NewBuffer:Fetch(instance_name)

And return something like this:

NewBuffer:Put(instance_object)

If you stick to a system like this, you can make sure that no instances are lost. (However, instances ARE unpreventably lost upon death if the container it lies within is no longer referenced, and this can lead to drastic memory leakage. So make your own custom death function if you're worried about this, or do something like disabling GUI reset upon death.)

ReCycle/Class utilities module script (Class script by NoliCAIKS):
https://www.roblox.com/library/530464943/ReCycle

Script in action:
https://www.roblox.com/games/467912144/Cubic-Chunk-Testing
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Oct 2016 06:35 PM
I don't think you know how memory leaks work lmao
And a lot of what you said is very wrong anyways.
Report Abuse
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
25 Oct 2016 06:38 PM
Memory leaks occur when memory no longer in use isn't deallocated. I'm not wrong. Last time I checked, creating 80,000 instances, destroying them after creation, and severing any references to them still kept them in memory. It's just a problem I've faced before and I'd like to make my solution public.
Report Abuse
skppiy4000 is online. skppiy4000
Joined: 09 Oct 2008
Total Posts: 1945
25 Oct 2016 06:39 PM
Thank you for this ignore that guy
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Oct 2016 06:40 PM
"Last time I checked, creating 80,000 instances, destroying them after creation, and severing any references to them still kept them in memory."
You can't "severe" any references to them unless you know and can access those variables (or if the ref. is in a table, the table) in the first place

And your solution doesn't do anything, in fact if anything it makes things worse.

And yes, if you create 80k instances then destroy them, eventually they will all get GC'd unless there are references to them. If they didn't then why don't shooting games that use bullets get slower over time? Exactly.
Report Abuse
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
25 Oct 2016 06:43 PM
No, I looped 80k times, in a cycle of the following instructions:

initialize local variable, simple part
destroy said part, once the closure is exited, this part shouldn't have any references

I waited and waited, but no instances EVER got GC'd.

My solution must be doing something, as it helped me get my average memory usage down from 2.4GB to 210MB. It works-- there's no question about it.

And as for FPS games which do the same thing, who's to say that these games _don't_ use a similar method?

You don't have to use it. Trust me, this isn't an advertisement, I don't have anything to gain from this. But don't say other people can't and shouldn't use it.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
25 Oct 2016 06:47 PM
The garbage collector doesn't work from waiting...


Report Abuse
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
25 Oct 2016 06:48 PM
I know. But considering the GC runs in cycles, it should've gotten collected by that point. I had even tried making all of my references to the parts weak, but to no avail.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Oct 2016 06:52 PM
Your "solution" literally puts them in a table, if you knew anything about Lua you would realize why what you did doesn't help at all even if there were a problem.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Oct 2016 06:54 PM
The fact that you even think 80k parts is going to cause 2GB worth of memory to be used proves this whole thing is a lie.
Report Abuse
dekkonot is not online. dekkonot
Joined: 22 Dec 2010
Total Posts: 6685
25 Oct 2016 06:54 PM
Lemme just stick my head into this and say: You're wrong.

I just ran a test to confirm it, using this function:

http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#collectgarbage

While yes, after generating and destroying 30,000 parts, there is a jump in memory, if you wait a bit it starts to go down, confirming the parts are indeed being collected once references to them are removed.
Report Abuse
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
25 Oct 2016 06:56 PM
Did you even look at my script? How do you come to that conclusion?

It doesn't just put them in a table. Since, in my experience, instances that are the target of :Destroy() (and have no standing references) don't always free from memory (strangely, though, they do in Studio), I keep them in a table for storage, so new instances need not be created if some are available.

If you really would like to prove how this is entirely ineffective, please, don't hesitate to provide actual criticism besides something like:

"You don't know how this works, you idiot."

I would be interested in what really makes this 'ineffective' if such is the case.
Report Abuse
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
25 Oct 2016 06:58 PM
The 80k example was a sort of benchmark I ran months back. However, in the 2GB situation, the instance count climbed well over three million. Sorry for no clarification on that.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Oct 2016 07:00 PM
It doesn't work because even though the GC is a problem in RobloXPlayer (which I doubt it is), there is NOTHING YOU CAN DO ABOUT IT FROM LUA. You can't even force the GC to run a cycle on Roblox.

So what if you can "guarantee" no Instances are lost, that just means that any Instance that needs to be GC'd CAN'T BE GC'd because there's a reference to it in your table.
Report Abuse
dekkonot is not online. dekkonot
Joined: 22 Dec 2010
Total Posts: 6685
25 Oct 2016 07:05 PM
I personally have no experience with memory leaks, but this doesn't at all seem like something that should work. Instances _are_ collected by the GC, which means your system is moot, and there's not really anything your script can do to increase performance besides making sure you're not constantly creating new instances of the same properties.

If you're encountering memory leaks, that's a you problem, not a ROBLOX problem.
Report Abuse
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
25 Oct 2016 07:06 PM
Sorry for wasting your time. Somewhere along the line in the past, I must have been doing something wrong, as, apparently, I've run the old benchmark I created and the GC issue is fixed(?), to the extent that at least I don't experience the old problem. Please forgive my temperament getting so heated.
Report Abuse
badfitz67 is not online. badfitz67
Joined: 03 Jun 2010
Total Posts: 13165
25 Oct 2016 07:09 PM
"Sorry for wasting your time. Somewhere along the line in the past, I must have been doing something wrong, as, apparently, I've run the old benchmark I created and the GC issue is fixed(?), to the extent that at least I don't experience the old problem. Please forgive my temperament getting so heated."

impossible. no one is this level headed on the internet


"You took my grandfathers cards, so I took your bodyguards' kidneys"
Report Abuse
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
25 Oct 2016 07:12 PM
I say this only because you'd generally need to be pretty lucky if you were to be forgiven by people like cntkillme/Flux_Capacitor.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image