destroy() vs release()

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
yakisoba
Prole
Posts: 2
Joined: Mon Apr 06, 2020 3:59 am

destroy() vs release()

Post by yakisoba »

If I want to free a physics body from memory, is there any difference between calling Body:destroy and Object:release?
Eir
Prole
Posts: 1
Joined: Fri Apr 10, 2020 8:56 am

Re: destroy() vs release()

Post by Eir »

(if you couldn't find an answer yet)
I cannot answer directly but this is what you could try to find out :
Create an object with a fixture "fixture".
Destroy() is supposed to delete the object and its fixtures, so using destroy(), "fixture" will be deleted.

Release the object and try to use a function on "fixture".
If it has been deleted as well, you should get an error ( => "After this method has been called, attempting to call any other method on the object or using the object as an argument in another LÖVE API will cause an error." from Object:release() documentation).
yakisoba
Prole
Posts: 2
Joined: Mon Apr 06, 2020 3:59 am

Re: destroy() vs release()

Post by yakisoba »

Okay, after some testing and poking around, I found that Object:release simply disables the body's Lua reference. The body itself will still remain active within the physics world. Body:destroy removes it from the world and disables its reference.

In the C++ source, destroy() also calls release(), but not vice-versa.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 95 guests