I was trying to unrequire the lua file created by spriteloq, but unrequiring the scene isn't working for me either. Here's what I've got. This should answer your questions better than my prattling. As for the names of things, "TitleScreen" is the scene I'm leaving, and "targetPractice" is the one I'm going to. pManFactory is the spriteloq sprite factory, pMan is the sprite. And I'm getting an error at unrequire() in the last line of the last function.
@w2md, I use performWithDelay when I change scene. Here's typical scene change routine that I use. I haven't noticed any memory leak issue with this:
1
2
3
4
5
6
7
8
9
10
11
| -- when changing to a screen that has no need for spriteFactory
function changeScene(event)
local function launchWithDelay()
spriteFactory:dispose();
spriteFactory = nil;
director:changeScene("levels", "flip");
unrequire("level1.lua");
end
-- a few lines of code here for things that need to happen before timer launches
timerStash.newTimer = timer.performWithDelay(100, launchWithDelay);
end |
@Naomi,
Unrequire still gives me this error:
Runtime error
...ini3/Desktop/W2MD/Projects/GumChucks/TitleScreen.lua:194: attempt to call global 'unrequire' (a nil value)
stack traceback:
[C]: in function 'unrequire'
...ini3/Desktop/W2MD/Projects/GumChucks/TitleScreen.lua:194: in function 'onRelease'
...sers/MacMini3/Desktop/W2MD/Projects/GumChucks/ui.lua:97: in function <...sers/MacMini3/Desktop/W2MD/Projects/GumChucks/ui.lua:34>
?: in function <?:215>
I even changed the way I was writing it to match your format (i.e. unrequire("TitleScreen.lua") ) and used a timer as well.
My memory usage for the TitleScreen is 470 kB when I first open up the app (it's my first screen). And targetPractice starts off at 147kB if I go straight there from main.lua instead of going to TitleScreen first. However, after my director:changeScene to targetPractice from TitleScreen my memory usage is up at 505 kB. And everytime thereafter when I go back to the TItleScreen my memory increases by about 30 kB.
Any other suggestions? I really appreciate you guys ironing this out with me.
Thanks,
-Matt
W2MD
Do you have the latest version of the API? The error says unrequire doesn't exist which probably means you're running an older version of the API. FYI, unrequire is a function in loq_util. It's not part of the Corona API.
If you're seeing an increase in your memory from repeatedly loading the same module, it sounds like you have a memory leak as well.
@w2md, a quick note to let you know that I added the second type I use. See comment #3 with edits.
Thanks Don,
Changing out the spriteloq api files made a big difference just by itself. Now the memory only goes up to 350 kB when I transition to the targetPractice scene. I did notice that unrequire() doesn't clear up any memory at all, which makes this even more confusing. What is it that is typically unrequired? The scenes that director is cleaning up? Or is it the spriteFactories or the sprites themselves?
Thanks!
-Matt
W2MD
The purpose of unrequire is to reclaim memory from modules you no longer need. So for example in my game I have levels has modules. When the player finishes playing level 1, it's unlikely they'll go back and play level 1 again so I unrequire it to reclaim that memory. Depending on what you have in your level files that could be significant.
It only matters when you start having hundreds of levels though. And the clean up isn't 100%, but should be a significant reduction.
UPDATE: I also perform an unrequire inside of the Spriteloq API when you dispose of SpriteFactories to reclaim the application memory used by the loaded spritesheet metadata. If you're loading lots of sheets and levels, this can add up. Is it significant enough to fret over it? Maybe, maybe not. But when you do get a real memory leak it does make it easier to diagnose misbehaving code.
That explains everything really well. Thanks so much Don. It's great working with well made software that cleans itself effectively.
I am running into a little issue with the new api modules though. When I put loq_sprite.lua in, my retina-display and non-retina-display sprites are unusually large. It doesn't seem to effect the iPad build I made at all. It's probably some really simple difference in the code of the api.
Is there somewhere that lists off the differences in each version of the api libraries?
Thanks,
Matt
W2MD
Hi w2md, I usually post to twitter or to the forum whenever I update the API. It's pretty infrequent. Whenever there's a major update I send an email to the mailing list.
The next update will include a major API change along with an update to Spriteloq. There are two branches of the API. One for those using an old version of Corona that don't include features in teh daily builds and one that supports the latest daily build. So if you're using build 591 or early there's a separate link on the downloads page for you.
There'll be a twitter post, forum post, blog post, and mailing list post when the next update occurs.
I responded to you in email already, but for anyone else curious as to what the issue this is referring to it's about dynamic spritesheet resolution / scaling. The next Spriteloq and API update will include the ability to export you swfs at different scales and have them incorporated into your projects easily!