Forum Discussion
romrador
10 years agoHonored Guest
Oculus Platform Unity Integration Memory Optimization
Hi devs! I'm a member of the Platform SDK team and I'm working on improving the memory usage of the Oculus Platfrom Unity integration. I started to profile our memory usage and there is definite...
owenwp
10 years agoExpert Protege
The main issue is that the old version of mono used by Unity has a garbage collector that is non-compacting and non-generational. So small allocations last longer, inevitably add up to a full GC which is guaranteed to drop frames. Allocations of varying lifetimes also create bubbles in the heap which cannot be defragmented, which can even cause you to run out of memory eventually. (from experience on a shipped title: using unity for dedicated game servers is a mistake)
For one time loading this is certainly fine. It is not uncommon to manually trigger garbage collection immediately before and after loading data before rendering starts, which fixes all those problems because then you are not interleaving allocations with short and long lifetimes. If you can design the API so that any state you are storing until shutdown gets pre-allocated upfront, before any temp allocations, that helps.
Operations that are not every frame but must still be called many times, like getting room or user data, should avoid allocation on the managed heap where possible, otherwise you will see dropped frames eventually. Since the GC is not generational, even if it is not every frame you will build up a debt that eventually has to be paid.
For one time loading this is certainly fine. It is not uncommon to manually trigger garbage collection immediately before and after loading data before rendering starts, which fixes all those problems because then you are not interleaving allocations with short and long lifetimes. If you can design the API so that any state you are storing until shutdown gets pre-allocated upfront, before any temp allocations, that helps.
Operations that are not every frame but must still be called many times, like getting room or user data, should avoid allocation on the managed heap where possible, otherwise you will see dropped frames eventually. Since the GC is not generational, even if it is not every frame you will build up a debt that eventually has to be paid.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago