Is there a way to know the system memory used by a Object ?

Well, I think everything is in the title ;)

EDIT : I have been thinking again to my problem. Actually I don't need to know exactly which object owns a particular texture or mesh. I only need to know what are the loaded textures and meshes.

The Unity profiler sadly shows little information about the memory. If there was a way to list what assets are currently loaded with their name and memory footprint, that would definitively suits my need ;)

For simple objects you can use the sizeof operator

Debug.Log ("A Vector3 Object Uses "+sizeof (typeof(Vector3))+" bytes");

or possibly just

Debug.Log ("A Vector3 Object Uses "+sizeof (Vector3)+" bytes");


To see all allocated memory, you can use the Garbage Collector data (.Net stuff)

Debug.Log ("Total allocated memory : " + System.GC.GetTotalMemory (0) + " bytes");

The bad thing when using GC is that it will increase steadily until GC gets called (when there isn't any more memory left for the program to use) and then drop quite a lot just to start over and increase again.

The good thing is that you know exactly how much memory is used.

If you want more info about GC, just google it (or Garbage Collector).

I don't know of any way to determine the memory allocated by a single object. My understanding is that the vast majority of memory usage is in textures so object memory probably isn't a massive factor. If you have pro you can check out the Profiler to work out hoe much of the memory usage is object metadata:

I don't think there is any way of determining how much memory is "owned" by an object. In order to answer that you'd have to consider object size (sizeof, see The Stones answer), memory allocations (see Petroz answer) and object ownership.

If I have a game object with two different scripts, let's call them Consumer and Producer, and Consumer asks Producer to produce an item (allocate memory). Should you count the allocated memory to belong to the Consumer or the Producer?

The problem gets trickier when you use shared references. If two scripts reference the same texture you can't really say that object A use sizeof(A) + size of texture and object B use sizeof(B) + size of texture.

Well, I think everything is in the title ;)

Though I guess you can argue that both objects use sizeof + size of texture. It all depends on what you're trying to look for. So I can't really say everything is in the title, because there are so many ways to look at your question. ;)

This thread is old. I recommend the “Resource Checker” asset in the store.