Skip to content

Proper Garbage Collection

Compare
Choose a tag to compare
@jaipack17 jaipack17 released this 17 Mar 08:07
· 11 commits to master since this release
b0b1a6b

Implemented proper garbage collection in the library for the Engine and all its Physics Objects to reduce chances of memory leaks in key areas. All problems listed in #33 have been dealt with.

  • Added Janitor to src/Utilities
  • Implemented garbage collection in Engine.lua
    • Handled how connections are disconnected.
    • Engine:Stop() no longer destroys connections of the Engine (Updated, Started, Stopped, ObjectAdded, ObjectRemoved). It simply pauses the engine by disconnecting the primary RenderStepped connection.
    • Added Engine:Destroy() - Disconnects all events, destroys all rigid bodies, points and constraints and also makes the engine unusable.
  • Implemented garbage collection in Point.lua
    • Added Point:Destroy() - Destroys the point's GuiObject, destroys the point's parent constraint (if any), and is no longer part of the engine.
  • Re-wrote garbage collection in Constraint.lua
    • Re-implemented Constraint:Destroy() - Destroys the constrain't GuiObject, destroys the constraint's parent rigid body (if any), destroys its points (point1 and point2), and is no longer part of the engine.
  • Re-wrote garbage collection in RigidBody.lua
    • Re-implemented RigidBody:Destroy() - Destroys all events (Touched, TouchEnded, CanvasEdgeTouched), destroys its GuiObject, destroys its constraints (edges) which subsequently destroys all its points (vertices), and is no longer part of the engine.
    • Destroying the GuiObject of the rigid body via Instance:Destroy() will trigger RigidBody:Destroy().
    • Destroying an edge of the rigid body via Constraint:Destroy() will trigger RigidBody:Destroy().
    • Destroying a vertex of the rigid body via Point:Destroy() will trigger RigidBody:Destroy().

Bugs Introduced by these Changes

  • RigidBody:Destroy()'s keepFrame: boolean parameter no longer determines if the GuiObject of the rigid body is destroyed when the method is called. Passing it in as true will still end up destroying the GuiObject. This bug shall be fixed in v0.7.1 along with bug #37.