Results 1 to 37 of 37

Thread: Threading and leaking memory - a demonstration

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    99

    Threading and leaking memory - a demonstration

    There's a good deal of web chatter regarding VS/CLR threading creating memory management problems. Specifically, the issue seems to be that overactive threading creates noticeable memory leak issues.

    I'm sorry to say that this is consistent with what I'm seeing as I add multi-threading to my current app.

    For the guru's, attached please find a small project demonstrating the issue. It's pretty simple. It has one form, one button and one label. It has a class that manages a run/control loop and another that is run by the control loop. (This structure mimmicks my production code.) I suggest running it in the debugger. Don't know what it might perpetrate in the real world.

    I'm currently running VS2008 under Vista in a 32 bit environment.

    On my machine (a 2.4 gig, 4 core AMD with 16 gig mem - using only 4 of course), this locks after ~7k repeats (running the test is a good excuse to refresh the coffee input device). Not that there could be any doubt, but I am no longer any sort of kernel guru. However, using Process Explorer (http://technet.microsoft.com/en-us/s.../bb896653.aspx ), I was able to determine that in the end, this program dies trying to make a memory allocation associated with a thread creation. Between this and the fact that the run of the program shows a slight but noticeable upward trend in memory utilization, AND that my production program sucks down the memory like a black hole when running in multi thread mode (much bigger classes/routines), I conclude that memory is leaking.

    My questions:
    1) Do you have any suggestions for fixing the current style of thread use? (i.e. changing where the threads are declared, calling System.GC, doing something with Finalize, setting the thread to Nothing on completion, etc.) I've tried a number of these but I'm sure this audience will have more than I've thought of.

    2) Does anyone know off hand if using a Threadpool mitigates this problem?

    3) Any ideas (hopefully fairly simple) that would allow me to multi-thread (or process for that matter) that don't kill the OS environment.

    If you really want to check this out and/or help and have only a 2005 environment, let me know and I'll build a version and upload it.

    Thanks in advance.

    PS. Please forgive in advance if there's a simple fix/explanation for this someplace. As I said above, I've googled this at some length and find a great many questions but a noticeable lack of answers. In that case, just point me to it!
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width