I have an application that creates scene kit textures using the following:
let texture = SKTexture(image: image)
The problem is that after several calls, the application crashes due to low memory.
I really only need the most recently created texture so when creating a new one, the preview ones' memory can be released, however, Scene Kit seems to be holding on to these textures even when they aren't being used anymore (the nodes are no longer part of the scene).
How can I manually tell Scene Kit to release the memory and cache of the texture so I don't get into the low memory crashing situation?
Also, I know that the SceneKit documentation recommends removing all references to the texture by removing nodes and such, but that should be happening and yet the Texture is not being released. Is there a good way of debugging and seeing what's holding on to the reference?
In re-reviewing the code, I'm creating a scene to hold the image to be rendered in the primary scene (whose node doesn't change). Basically, there is an object in the scene that can display an image or a video and that gets changed out by returning a Scene which is used as the material diffuse contents.
let texture = SKTexture(image: image)
let sprite = SKSpriteNode(texture: texture)
let scene = SKScene(size: sprite.size)
sprite.position = CGPointMake(CGRectGetMidX(scene.frame), CGRectGetMidY(scene.frame));
scene.addChild(sprite)
And then being used here:
primaryObjectMaterial.diffuse.contents = scene
I would expect once the scene's node material contents are changed, this scene (and the texture and image) would be released as there would no longer be any references to it but perhaps the caching system is hanging onto something or I'm doing something wrong?