Delete chunk - love.filesystem.load

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Delete chunk - love.filesystem.load

Post 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 :)
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Delete chunk - love.filesystem.load

Post 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

User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Delete chunk - love.filesystem.load

Post 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
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Delete chunk - love.filesystem.load

Post 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 ?
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Delete chunk - love.filesystem.load

Post 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?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Delete chunk - love.filesystem.load

Post 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.
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Delete chunk - love.filesystem.load

Post by Volgoza »

Yes, i now.
But my code "require (file)" itself contains again it tables.

Code: Select all

table = {}
Nope. Again error.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Delete chunk - love.filesystem.load

Post by Plu »

Can you post the .love file so we can have a look?
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Delete chunk - love.filesystem.load

Post by Volgoza »

My game weighs ~60 mb...

But 1 minutes, i create test for you.
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Delete chunk - love.filesystem.load

Post 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.
Attachments
test.love
(5.16 MiB) Downloaded 231 times
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 63 guests