Perspective / Camera library and general cleanup of objects..

Greetings,

In my latest project, I have the Camera view that’s part of the Perspective library.  I’ve used this in multiple projects and all seems to go well.

Basically I have a stage with many platforms(50).  The platforms are ‘snapshots’ objects because I use effect filters on them (and remove the filters).  Within the snapshot object, I have a couple layers for detailing purposes-display image objects being overlayed by inserting them into a snapshot group… So for the platforms , the code looks something like this (I’m not at my coding computer so bear with me):

Near top, declaration of the Camera/Perspective library:

local perspective = require("perspective") local camera = perspective.createView()

local platformSnapshot = {} 

Then have a ‘for i =1, 50 do’ … for purposes of keeping things tidy I’m only showing parts of my overall code, I’ve already created the objects previous to this:

platformSnapshot[i].group:insert( detailLayer ) camera:add(platformSnapshot[i], 1)

This seems pretty typical and works as expected.  But I noticed that memory was leaking on scene switch that is directly related to the Platforms (I tried commenting out the platforms and the memory wasn’t leaking).

For cleaning up my objects, the scene goes to a temporary scene… finds the previous, then removes previous scene.  In the previous scene (the one with platforms), using the Composer function- on destroy (I forget actual name atm)… I would have:

camera:destroy() camera=nil

So I decided to add a ‘for i=1, 50 do’ loop that basically removes each platformSnapshot object - which then cured the memory leak. 

I was always under the assumption you can just remove the display group, which will remove all of it’s children then set it to nil and that’s that…

Does Camera/Perspective library function differently or is there some probable loophole in my code??  Or maybe to do with Snapshot groups embeded in Camera view ??

All camera:destroy() does is loop through and display.remove()'s each layer, then the camera object itself - that means if an object has anything that isn’t completely destroyed when display.remove hits it, it’ll leak memory. That said, I just made a little tweak to Perspective to only display.remove the layers and not the objects inside each layer, so see if that fixes your problem.

  • Caleb

All camera:destroy() does is loop through and display.remove()'s each layer, then the camera object itself - that means if an object has anything that isn’t completely destroyed when display.remove hits it, it’ll leak memory. That said, I just made a little tweak to Perspective to only display.remove the layers and not the objects inside each layer, so see if that fixes your problem.

  • Caleb