I have a Dictionary of SKTextures that caches recently loaded textures (70 or so). I'm releasing them when a memory warning is received, like this:
let keys = textures.keys.array
for key in keys {
textures[key] = nil
}
This works great, and I can see in the Xcode debugger that the memory is actually being freed.
When I try to release them on applicationDidEnterBackground(), however, it doesn't look like it fully works. The memory usage drops by a small inconsistent amount (5-20 MB), but the rest of it doesn't get freed until the app is resumed.
Is this a quirk with the debugger and the memory is being freed? Or does the garbage collector not have enough time to clean up before the app is suspended? Or am I doing this all wrong?
Update: I'm pretty sure it's related to SpriteKit automatically pausing the SKView when entering the background. This is easily reproducible by pausing the view manually just before releasing the textures. Then the memory won't be freed even when the memory warning is received.