| Author |
Message |
CliffCawley
Joined: 04 Mar 2013 Posts: 1 Location: Australia
|
Posted: Mon Mar 04, 2013 9:14 am Post subject: Memory Profiler showing k__BackingField for Property names |
|
|
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 |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6345 Location: Red Gate Software
|
Posted: Tue Mar 05, 2013 1:29 pm Post subject: |
|
|
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;}. _________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
|
|
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