Page 1 of 2

Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 10:16 am
by Volgoza
Hello again. :)

How i can delete chink from code : chunk = love.filesystem.load ( name )?
My game spends more RAM and i want delete graphics with RAM after exit from locations.

Example:
I have 2 locations:
I entered in 1 location and i load graphics and code for this location. -> i left 1 location and i want delete source for 1 location and load source for 2 location.

How i can get it?

Sorry for my english :)

Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 10:25 am
by Plu
You can simply unset the variable(s) that holds the graphic and the garbage collector will pick it up. Just make sure you get rid of all the references if there are multiple.

Code: Select all


img = love.graphics.newImage( 'someImage.png' ) 

if level == 2 then
  img = nil -- this will remove the image from memory
end


Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 10:35 am
by Volgoza
Good.

Can i delete all table in one moment?

table = {
img 1 = love.graphics.newImage( 'someImage1.png' )
img 2 = love.graphics.newImage( 'someImage2.png' )
}

Can i make it through "for"?

And this:

Code: Select all

 img = nil
dosn't work

Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 10:42 am
by Plu
You can remove the entire table by just setting the table to nil (but again, make sure you've removed all references to it)

Code: Select all

table = nil
(Also it's a very bad idea to make a variable called table, because table is a default variable with a bunch of functions and you'll probably destroy some libraries. But I'm assuming this is just an example.)

What isn't working about img = nil ?

Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 10:50 am
by Volgoza
I delete all tables from 2 location and run again this and i take error what can't read table, but when i entered in location 2 i use require ( file ) where i keep all tables.

Maybe i need use love.filesystem.load instead of require?

Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 10:54 am
by micha
When you do

Code: Select all

table = nil
then the varaible "table" does not exist anymore. Try

Code: Select all

table = {}
instead. This should replace the original table by an empty table.

Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 11:02 am
by Volgoza
Yes, i now.
But my code "require (file)" itself contains again it tables.

Code: Select all

table = {}
Nope. Again error.

Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 11:16 am
by Plu
Can you post the .love file so we can have a look?

Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 11:28 am
by Volgoza
My game weighs ~60 mb...

But 1 minutes, i create test for you.

Re: Delete chunk - love.filesystem.load

Posted: Thu Nov 21, 2013 11:48 am
by Volgoza
Here test file.

Left click - enter in next game mode, right click - previous game mode.

Need that after enter in first game mode - sun deleted from ram and in again i'm enter in second mode - sun again load.