Menu

#1 Memory Leak

v1.0_(example)
open
nobody
None
5
2012-09-14
2009-09-25
Anonymous
No

I've been using the simulator to build a computer similar to this relay computer (http://web.cecs.pdx.edu/~harry/Relay/). I continually watched the sim's memory usage grow past 500mb as I designed designed and saved ICs. I was unable to wire up a test ALU (contained 18 UserInputs, 8 UserOutputs, and 4 custom ICs) because the sim used about 1GB of memory and my pc became unresponsive.

I have been able to workaround the problem somewhat by continually saving my work, then closing the program.

Discussion

  • Nobody/Anonymous

    You can send me your circuit file? Also, does it just leak as you design and create ICs, or does the leak progress continually as the program runs?

     
  • Nobody/Anonymous

    Memory usage continues to grow as I use the program. If it's left idle, memory usage won't increase. It will grow as I use the workspace, create ICs, delete the circuits from the workspace, etc.

     
  • Josiah

    Josiah - 2009-09-25

    I ran it with the debugger in visual c# express 2008, and noticed memory usage steadily climbed to around 128mb as it was doing before. However, I minimized the program for a while and memory usage dropped to about 19mb.

     
  • Josiah

    Josiah - 2009-09-27

    So here's your Circuit constructor:

    public Circuit()
    {
    wires = new Dictionary<terminal, terminal="">();
    toFlip = new SyncQueue.ConcurrentQueue<keyvaluepair\<terminal, terminal="">>();
    this.ListChanged += new ListChangedEventHandler(Circuit_ListChanged);</keyvaluepair\<terminal,></terminal,>

            Thread t = new Thread(PropagationThread);
            t.Priority = ThreadPriority.BelowNormal;
            t.IsBackground = true;
            t.Start();
    
        }
    

    I'm guessing the overhead from each thread that is created for a circuit is the cause of the memory usage issues and general slowness as my ICs begin to form a "complete" cpu. I enabled the thread count column in the processes tab of the task manager, and sure enough, thread count for the program after I loaded my saved workspace was near 600.

    I haven't looked at the code thoroughly, but I'm guessing these threads run for the lifetime of the program. Perhaps, for now, you could change it so only the threads for the circuits in the workspace are running, and not all circuits in the IC list. However, this would most likely still be a problem as more complex ICs are added to the workspace.

     
  • Steven Kollmansberger

    I suspected the same. I think it may be "worse than that", in a sense... A running thread can never be garbage collected; and if the thread is running it might keep the circuit from being garbage collected as well. I did a modification where the thread is stopped when the circuit is no longer in use (allowing the thread and the circuit to be garbage collected), but that didn't eliminate the memory leak entirely. So I'm still searching.

    An easy way to reproduce the memory leak is to create an IC, put a dozen of them on the canvas, copy them to the clipboard, and then delete-paste-delete-paste, etc. The memory usage climbs steadily even though the overall complexity of the circuit stays the same.

    I also suspected the undo tree might be at fault, so I added a method to clear it on command. Neglible effect.

     

Log in to post a comment.