SnapShot memory leak?

Hi, I’m trying to use snapshots to optimize my game, but I’m facing an issue. I use the removeSelf method to clear those snapshots but it seems that it’s not enough. The system memory is growing bigger and bigger each time I reset my scene. I’m sure this leak is due to snapshot because when I just replace snapshots by display groups, the leak disappears.

I know that when you remove a display group parent, all its display objects are removed. Is it the same for snapshots?

Here is some basic code to illustrate what I’m saying:

print("init") if snaps then for i=#snaps,1,-1 do snaps[i]:removeSelf() snaps[i] = nil end end snaps = {} for i = 1, 30 do local snap = display.newSnapshot(640, 980) snaps[#snaps+1] = snap for j=1,100 do local b = display.newImageRect(snap.group, "bloc.png", 50, 50) end end

This piece of code is executed each time I reset my game and it produces something like in the terminal:

17:32:33.733  Platform: iPhone / x64 / 10.0 / GeForce GTX 680/PCIe/SSE2 / 4.5.0 NVIDIA 385.41 / 2017.3068 / fr_FR | FR | fr_FR | fr

17:32:33.733  Loading project from:   C:\Users\David\Documents\GitHub\dragonvslava

17:32:33.733  Project sandbox folder: C:\Users\David\AppData\Local\Corona Labs\Corona Simulator\Sandbox\dragonvslava-9C1D21FFA0693D9EFABA8539C3F9629A\Documents

17:32:33.935  init

17:32:34.189  System Memory: 1074 KB Texture Memory: 444.013 MB

17:32:35.176  System Memory: 1341 KB Texture Memory: 444.556 MB

17:32:36.106  System Memory: 1332 KB Texture Memory: 444.556 MB

17:32:37.048  System Memory: 1319 KB Texture Memory: 444.556 MB

17:32:37.979  System Memory: 1310 KB Texture Memory: 444.556 MB

17:32:38.922  System Memory: 1321 KB Texture Memory: 444.556 MB

17:32:39.864  System Memory: 1341 KB Texture Memory: 444.747 MB

17:32:40.794  System Memory: 1343 KB Texture Memory: 444.747 MB

17:32:41.735  System Memory: 1336 KB Texture Memory: 444.728 MB

17:32:42.669  System Memory: 1260 KB Texture Memory: 444.728 MB

17:32:43.018  init

17:32:43.270  System Memory: 1622 KB Texture Memory: 445.033 MB

17:32:44.211  System Memory: 1731 KB Texture Memory: 445.052 MB

17:32:45.139  System Memory: 1775 KB Texture Memory: 445.052 MB

17:32:46.087  System Memory: 1693 KB Texture Memory: 445.052 MB

17:32:47.016  System Memory: 1761 KB Texture Memory: 445.052 MB

17:32:47.955  System Memory: 1717 KB Texture Memory: 445.052 MB

17:32:48.888  System Memory: 1811 KB Texture Memory: 445.052 MB

17:32:49.825  System Memory: 1723 KB Texture Memory: 445.052 MB

17:32:50.772  System Memory: 1741 KB Texture Memory: 445.033 MB

17:32:51.708  System Memory: 1635 KB Texture Memory: 445.033 MB

17:32:52.461  init

17:32:52.746  System Memory: 2117 KB Texture Memory: 444.728 MB

17:32:53.712  System Memory: 2212 KB Texture Memory: 444.747 MB

17:32:54.644  System Memory: 2282 KB Texture Memory: 444.747 MB

17:32:55.583  System Memory: 2275 KB Texture Memory: 444.747 MB

17:32:56.521  System Memory: 2272 KB Texture Memory: 444.747 MB

17:32:57.455  System Memory: 2265 KB Texture Memory: 444.747 MB

17:32:58.388  System Memory: 2279 KB Texture Memory: 444.747 MB

17:32:59.327  System Memory: 2274 KB Texture Memory: 444.747 MB

17:33:00.342  System Memory: 2202 KB Texture Memory: 444.728 MB

17:33:01.278  System Memory: 2124 KB Texture Memory: 444.728 MB

17:33:01.965  init

17:33:02.220  System Memory: 2480 KB Texture Memory: 445.119 MB

17:33:03.159  System Memory: 2581 KB Texture Memory: 445.138 MB

17:33:04.091  System Memory: 2611 KB Texture Memory: 445.138 MB

17:33:05.032  System Memory: 2607 KB Texture Memory: 445.138 MB

17:33:05.975  System Memory: 2644 KB Texture Memory: 445.138 MB

As you can see, System Memory is growing bigger and bigger.

If you just replace display.newSnapShot with a display.newGroup, no problem:

17:47:18.192  Platform: iPhone / x64 / 10.0 / GeForce GTX 680/PCIe/SSE2 / 4.5.0 NVIDIA 385.41 / 2017.3068 / fr_FR | FR | fr_FR | fr

17:47:18.192  Loading project from:   C:\Users\David\Documents\GitHub\dragonvslava

17:47:18.192  Project sandbox folder: C:\Users\David\AppData\Local\Corona Labs\Corona Simulator\Sandbox\dragonvslava-9C1D21FFA0693D9EFABA8539C3F9629A\Documents

17:47:18.384  init

17:47:18.656  System Memory: 1081 KB Texture Memory: 32.274 MB

17:47:19.632  System Memory: 1343 KB Texture Memory: 32.817 MB

17:47:20.571  System Memory: 1332 KB Texture Memory: 32.817 MB

17:47:21.499  System Memory: 1328 KB Texture Memory: 32.817 MB

17:47:22.435  System Memory: 1317 KB Texture Memory: 32.817 MB

17:47:23.381  System Memory: 1306 KB Texture Memory: 32.817 MB

17:47:24.312  System Memory: 1335 KB Texture Memory: 33.008 MB

17:47:25.257  System Memory: 1350 KB Texture Memory: 33.008 MB

17:47:26.191  System Memory: 1350 KB Texture Memory: 32.989 MB

17:47:27.130  System Memory: 1271 KB Texture Memory: 32.989 MB

17:47:27.720  init

17:47:27.964  System Memory: 1333 KB Texture Memory: 32.874 MB

17:47:28.893  System Memory: 1337 KB Texture Memory: 32.893 MB

17:47:29.830  System Memory: 1334 KB Texture Memory: 32.893 MB

17:47:30.769  System Memory: 1343 KB Texture Memory: 32.893 MB

17:47:31.703  System Memory: 1325 KB Texture Memory: 32.893 MB

17:47:32.643  System Memory: 1316 KB Texture Memory: 32.893 MB

17:47:33.580  System Memory: 1348 KB Texture Memory: 32.893 MB

17:47:34.521  System Memory: 1348 KB Texture Memory: 32.893 MB

17:47:35.451  System Memory: 1342 KB Texture Memory: 32.874 MB

17:47:36.393  System Memory: 1258 KB Texture Memory: 32.874 MB

17:47:37.017  init

17:47:37.263  System Memory: 1338 KB Texture Memory: 32.416 MB

17:47:38.210  System Memory: 1324 KB Texture Memory: 32.435 MB

17:47:39.136  System Memory: 1320 KB Texture Memory: 32.435 MB

17:47:40.085  System Memory: 1350 KB Texture Memory: 32.435 MB

17:47:41.012  System Memory: 1345 KB Texture Memory: 32.435 MB

17:47:41.959  System Memory: 1333 KB Texture Memory: 32.436 MB

17:47:42.895  System Memory: 1340 KB Texture Memory: 32.435 MB

17:47:43.832  System Memory: 1350 KB Texture Memory: 32.435 MB

17:47:44.761  System Memory: 1354 KB Texture Memory: 32.416 MB

17:47:45.710  System Memory: 1260 KB Texture Memory: 32.416 MB

17:47:46.640  System Memory: 1261 KB Texture Memory: 32.416 MB

17:47:47.585  System Memory: 1264 KB Texture Memory: 32.416 MB

Please update to the latest public release (2017.3135). We addressed several memory leaks since 3068.

Rob

Always update to the latest version before asking some help, thank you Rob, problem solved :wink:

Please update to the latest public release (2017.3135). We addressed several memory leaks since 3068.

Rob

Always update to the latest version before asking some help, thank you Rob, problem solved :wink: