- Home /
Memory usage of gameobject list
I'm not sure how Unity stores lists. Say I have a list of game objects. Is each list element a pointer to, or a copy of the game object?
I'm asking because I need to store game objects, but I think all I'll need is the position, and I'm wondering if I'd save RAM by making a Vector3 List rather than a GameObject List. The game objects contain quite a lot of variables.
Answer by TheSOULDev · Aug 29, 2017 at 10:55 PM
As far as I know, saving GameObjects in a list saves their reference, meaning that all you have is a pointer to the GameObject, and as far as I know two pointers (for the previous and the next atom), I've head somehwere that the C# list implementation is a two-way linked list. What you're trying to do is micro optimization and I suggest you stay away from it if you want to spend your time efficiently and have readable code. Whether you save the object to the list as a Vector3 or a GameObject it woun't change the fact that the GameObject's components will expend system memory when active.
Also, the general rule of optimization during development is that you don't optimize unless your game runs like crap.
The first part is correct. Though a generic "List" is not a linked list. It's just a wrapper for a native array with additional capacity to avoid frequent re-allocation.
Though i've often read that beginners confuse Arrays and Lists. They often call arrays "lists". I have the feeling that might be the case here as well.
Answer by ooblii · Aug 30, 2017 at 01:23 AM
If you think you’ll only every need the gameObject ‘s position, use a List of Transform, that way you’ll have access to any component you need. Hard to tell without seeing code, but if you use a List of Vector3 it will most likely be unreliable unless your gameObjects are static.
Having said that, if you’re looking to save RAM, worry about your texture and audio compression settings.
Your answer
![](https://koobas.hobune.stream/wayback/20220612133820im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How many instances of a Object are handled in Unity 1 Answer
How to improve the Performance of Removing Trees during runtime? 1 Answer
List elements all changing 1 Answer
JS Argument out of range 1 Answer