I became aware of this problem by reading another entry. I messed up a bit of SKShapeNode and really checked for the memory leak problem mentioned here.
I had an idea ...
Not a completely new idea, more revised. This great idea actually allowed me to use SKShapeNodes for my heart :)
pooling
Yes ... I just created the SKShapeNodes pool, which I reused as needed. Who cares what it does :)
You simply redefine the path when necessary, when done by returning to your pool, and it will wait for you to play with it again later.
Create an ivar or NSMutableArray property in your SKScene name SKScene and create it when you start SKScene . You can either populate the array with your form nodes during init, or create them as needed.
This is the quick method I created to grab a new node from the pool:
-(SKShapeNode *)getShapeNode { if (pool.count > 0) { SKShapeNode *shape = pool[0]; [pool removeObject:shape]; return shape; } // if there is not any nodes left in the pool, create a new one to return SKShapeNode *shape = [SKShapeNode node]; return shape; }
So, wherever you are in the scene, you need an SKShapeNode that you would do:
SKShapeNode *shape = [self getShapeNode];
When you finish using the node form, just return it to the pool and set the path to NULL, for example:
[pool addObject:shape]
I know this is a workaround, not an ideal solution, but certainly it is a very viable workaround for those who want to use a large number of SKShapeNodes and not flush the memory.
prototypical
source share