Hi there!
I´m trying to make a 360 image carousel in RealityView/SwiftUI with very large textures. I´ve managed to load one 12K 360 image and showing it on a inverted sphere with a ShaderMaterialGraph made in Reality Composer Pro. When I try to load the next image I get an out of memory error. The carousel works fine with smaller textures.
My question is. How do I release the memory from the current texture before loading the next?
In theory the garbagecollector should erase it eventually?
Hope someone can help =)
Thanks in advance!
Best regards, Kim
Hello @Kito7777
The Swift programming language does not use a garbage collector. Instead, Swift uses automatic reference counting to manage memory. If you are coming from a language that does use a garbage collector, like C#, Java, or Go, you should take some time to understand the benefits and tradeoffs a language like Swift provides. Automatic reference counting means memory that is no longer referenced by anything (its "reference count" is 0) is automatically released.
The correct way to deallocate your texture is to remove all references to it. For example, you may need to set all references to your texture to nil
. This might not be straight forward, especially if you are referencing the texture somewhere else in your program. If you share more about how you are storing your texture in memory, I'd be happy to troubleshoot it for you!
With all that said, 12K does seem very large. Are you sure this size is necessary? The sky dome in Presenting an artist's scene is only 8K and 7.6 MB, for comparison, although to be fair this texture is only for a dome shape and not a 360 sphere.