I am making an UndoRedoManager for a mobile RaceTrackEditor. The UndoRedoManager executes a Command and stores the command in a List so I can Undo or Redo it. I would like to know how much memory the List is using. How do I do this? I tried something like the code below but the logged amount stays the same, even with a million copies. void TestMemory() { for (int i = 0; i < 1000000; i++) { testList.Add( new MoveControlPointCommand( from, to, controlPoint ); } Debug.Log( SystemInfo.systemMemorySize+" Mb" ); }
systemMemorySize gives you the amount of memory in the computer, not how much is being used by your program. Try using the memory profiler.
Yes, profiler is a nice tool, but i want to notify low-end users when they reach a limit. The user would then be suggested to save the progress, and undo gets reset.
You should use the built-in low memory warning event for this purpose. Additionally, it is probably more user-friendly to instead/additionally use a circular buffer for your undo states, if you're concerned about the number of saved undos. This will allow the oldest undo states to be overwritten after a certain number of states is reached.