none
Tracing variable in memory RRS feed

  • Question

  • Hi,

    One my variables seem to be getting null. I am initializing the variable with null only in the constructor and breakpointing here does not help. I suspect if it is the garage collector who collected my variable. But I want to be sure, is there a way by which I can surely say if a variable was garbage collected? or is there a way by which I can check the state of the variable continously somewhere in memeory like finding its address and looking for its state in memory.

    Thanks a ton.

    Monday, October 31, 2011 6:10 PM

Answers

  • If you're initializing the variable with null, have you tried setting a breakpoint to make sure that it's getting set to something other than null?

     

    The GC will never collect the variable as long as it's rooted, which pretty much means, if your'e initializing it, it's not the GC - as long as you can still reach the variable, it will be rooted, and not eligible for GC...


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, October 31, 2011 6:30 PM
    Moderator
  • Hi,

    You can use CLR Profiler to investigate your application's memory allocation profile. You can use CLR Profiler to identify code that causes memory problems, such as memory leaks and excessive or inefficient garbage collection.

    Moreover, if you want to watch variables when debugging, you can use WinDbg or SOS.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, November 8, 2011 8:02 AM
    Wednesday, November 2, 2011 6:25 AM

All replies

  • If you're initializing the variable with null, have you tried setting a breakpoint to make sure that it's getting set to something other than null?

     

    The GC will never collect the variable as long as it's rooted, which pretty much means, if your'e initializing it, it's not the GC - as long as you can still reach the variable, it will be rooted, and not eligible for GC...


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, October 31, 2011 6:30 PM
    Moderator
  • Hi,

    You can use CLR Profiler to investigate your application's memory allocation profile. You can use CLR Profiler to identify code that causes memory problems, such as memory leaks and excessive or inefficient garbage collection.

    Moreover, if you want to watch variables when debugging, you can use WinDbg or SOS.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, November 8, 2011 8:02 AM
    Wednesday, November 2, 2011 6:25 AM