A little time ago I create a custom TweenService for my game and I have a doubt, apparently I've been testing the game to its extremes conditions and seems like there is memory leaks of practically all the Tweens? being not garbage collected I think. Why does this happen? and if you have any doubt or got any important info about this or something tell me
#Garbage Collection
1 messages · Page 1 of 1 (latest)
just reuse the tweens or destroy on completion instead of relying on gc
The thing is, for example, if you make an Tween (X) that Tweens the position, and then 2 frames after for example you make another Tween (Y), the Y will cancel X and if I destroy it without caring it may be used again in the script? I mean most of the time they're just going to nowhere but I mean, that is where the gc should really do his work
and Idk why it is not doing his work
you shouldn’t be relying on the gc to fix your optimization errors in the first place
I mean I cannot do more, there are no references to these Tweens so I really cannot do nth
you can just create a connection to tween.completed at the same time the tween is created
I have a method which is CleanPlay that what it does is connect to the Completed a function to Destroy it instantly when its completed
The thing is when a Tween stop another Tween for X reason, there is where I need the GC to work or maybe a lightful idea Idk
.completed will still fire if the tween is interrupted by another tween
I don't fire the completed because it is not completed, should I? because I think that's not how the real Tweens works
Solved, a reference still there lol
this is bad advice, the gc is an important feature of roblox luau and it is important to understand how it works
yes, if you hold a reference to anything it will stay in memory. this includes instances, and variables in modulescripts (even if you destroy the modulescript)
e.g part:Destroy() part:Clone().Parent=workspace works just fine. part:Destroy() doesn't actually destroy it, it just parents it to nil and you cannot re-parent it. you could do the same thing by doing part.Parent=nil. this is why sometimes certain instances dont need a parent to function
e.g Animation objects can be loaded by an animator even if the animation doesnt have a parent.
as for this, this is mostly true, but it is not tweens in general. it is tweening a specific property - you cannot tween position twice for example, the most recent one for that property will always take priority and override the previous one.
so if you tween position and color, then make another tween that tweens only color, the position tween should continue but the color will be overridden
yes, what was happening is that on my CleanPlay basically a connection was still referencing my Tween so the Tween was still there
just as a question, with CleanPlay it is directly cleaned the table and all that, should I do that is just cleaned with gc or?
idk what cleanplay is but basically all u gotta do is set things to nil or let them go out of scope to make them eligible for garbage collection
what I mean is what would be better:
- Automatically Destroy it and clean up the table
- Just clean all the references and let the GC handle it
because what I am doing is directly destroying it when is not needed more
dont install dumb 3rd party modules for gc. just clean up after yourself its not that hard
what thir dparty bro xd the tweenservice is fully written by me
I'm just saying which option would be the best
i think you overlooked the part when things also get garbage collected when they go out of scope