Red Gate forums :: View topic - Memory Profiler showing k__BackingField for Property names
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
ANTS Memory Profiler 7
ANTS Memory Profiler 7 forum

Memory Profiler showing k__BackingField for Property names

Search in ANTS Memory Profiler 7 forum
Post new topic   Reply to topic
Jump to:  
Author Message
CliffCawley



Joined: 04 Mar 2013
Posts: 1
Location: Australia

PostPosted: Mon Mar 04, 2013 9:14 am    Post subject: Memory Profiler showing k__BackingField for Property names Reply with quote

Hi!

I've been using ANTS Memory Profiler trying to trace a test leak I made.

I noticed that when viewing the Instance Retention Graph that instances that are assigned to Properties show up with a name as follows:

Code:

<Class> k__BackingField


For standard member variables it shows the name of the variable instead.

Why can't it show the Property name? Is that a bug that it doesn't?

If not it makes it difficult to find the correct instance without manually checking each variable of that type!

Am I missing something?
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6582

PostPosted: Tue Mar 05, 2013 1:29 pm    Post subject: Reply with quote

Thanks for contacting Red Gate.

Backing Fields are compiler-generated code that is necessary to create a private member to return when your code does not explicitly use a private member.

For instance, this class will have backing fields:
Code:

public class FileBrowser {
public List<string> Files { get; set; }
}

This class will not have backing fields, because a private member for the property accessor has been provided:
Code:

 public class FileBrowser
    {
        private List<string> m_fileList = new List<string>();
 public List<string> Files
        {
            get
            {
                return m_fileList;
            }
            set
            {
                m_fileList = value;
            }
        }
    }
If you want to be able to have your own variable names in the backing fields, you can write out your properties' get and set code explicitly instead of using the compiler-generated code you have with property {get;set;}.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group