'IOSurface' memory keeps increasing in SceneKit project
Asked Answered
P

0

6

This question is roughly related to this one.

I have a SceneKit project in which memory management has been a challenge (yes, even with ARC).

By loading images in a very specific way, by using weak variables in closures, and by setting SCNMaterials to nil prior to scene deallocation, I've been able to drastically improve the memory situation.

Here's how I'm loading the images:

DispatchQueue.global(qos: .background).async { [weak material] in
   let path = Bundle.main.path(forResource: "myString", ofType: "png")!
   let img = UIImage(contentsOfFile: path)

   material?.diffuse.contents = img
}

However, Instruments shows memory for category VM: IOSurface more or less continuously increasing without ever being adequately reclaimed. According to the documentation, IOSurface is related to image memory.

Here's what Instruments Allocations shows for VM: IOSurface (the memory here goes from about 17MB to about 69MB): enter image description here

For the above graph, I loaded and then unloaded a SceneKit scene several times.

Here's a graph that illustrates how this IOSurface memory relates to the overall memory footprint: enter image description here

And here are the callers of IOSurface: enter image description here

Now, you might think I should use UIImage(named:) instead of UIImage(contentsOfFile:), as the system caches the former in memory but not the latter. But using the former resulted in much worse memory statistics in my project.

I've seen this question on the matter, but it suggests that the problem is the device camera, which I'm not using.

Question: What can you tell me about how IOSurface relates to SceneKit, and how might I improve its memory usage?

Persiflage answered 13/12, 2022 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.