MemProf missing object construction

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
arkban
Posts: 4
Joined: Fri Jul 06, 2007 5:03 pm

MemProf missing object construction

Post by arkban » Fri Jul 06, 2007 5:17 pm

Hi,

I'm evaluating your Memory Profiler tool and so far I like it very much, but I'm running into a show-stopper of an issue. I have an object that is being constructed but MemProf doesn't catch it.

I believe the object in question is being leaked somehow (hence our evaluation of MemProf). So MemProf's missing the object construction is frustrating our efforts to fix the leak. The object contains a single byte[] array that is holding about 1.5 MB of data. The Type is detected by MemProf, just not the instances.

If this is a user error I'm not sure what I've done to cause it. I haven't messed with the default settings much. I did add an instance data rule to try and guarantee the object was profiled but it didn't work. (The issue occurred both before and after adding the rule).

Any ideas? I am evaluating MemProf looking to purchase, and as I've said this issue would remove MemProf from the lead position in my evaluations. Besides this issue I really do like MemProf.

Patrick

Running:
- Memory Profiler 3.0.113 Evaluation
- Windows XP SP2
- .Net 2.0

arkban
Posts: 4
Joined: Fri Jul 06, 2007 5:03 pm

More info

Post by arkban » Fri Jul 06, 2007 6:58 pm

Hi,

We have another entry point into our application that references that same class I described above and MemProf sees the object being created from.

Also I tried another memory profiler, AQTime 5, and it also seemed unable to see that class from the original entry point.

Patrick

Andreas Suurkuusk
Posts: 1029
Joined: Wed Mar 02, 2005 7:53 pm

Post by Andreas Suurkuusk » Sat Jul 07, 2007 7:17 pm

.NET Memory Profiler should track all instances created on the managed heap. In what way does it miss the construction of your object?

Is the instance not listed as a live instance when you expect it to be?
Is the class of the instance listed in the Types view, and does the profiler present any allocations of the class?

Can you provide some code that illustrate how the instance is created (and maybe some additional information about the class)?
Best regards,

Andreas Suurkuusk
SciTech Software AB

arkban
Posts: 4
Joined: Fri Jul 06, 2007 5:03 pm

Post by arkban » Sat Jul 07, 2007 8:03 pm

Yes to both your questions. I'll elaborate a bit.

MemProf lists the object in the "Types" list only after an instance is created. (I believe the listing late is by design? That would make sense.) But the object is never listed with any instances created or garbage collected. I've checked with the "Types" filter set "All" and "New or Removed instances"

I know an instance is created because I verified the creation: I launched the application with MemProf, attached the debugger (VS 2005), and put a break point on the object's creation to verify it was created. Then I removed the break points and ran the same code, creating a snapshot before and after the instantiation and didn't see the object's creation.

We have a rather big and complex application so I'm not sure which information about our code would be most useful in helping you. I'm not trying to avoid your question, I simply don't want to deluge you with lots of data that won't help. (Also due to IP reasons I need to appropriately tailor my responses.)

The class is a non-sealed, non-abstract public class (not struct). It contains a private byte[] and three private integers, no unmanaged memory or unsafe code. The byte[] is about 1.5 MB in size, and it is not detected as being allocated either (I'm assuming because the parent class isn't detected).

The class lives in an assembly that AFAIK has no special assembly attributes, build settings, or obfuscation. The assembly is not directly referenced by the entry point assembly; it is not listed in the entry point assembly's manifest. The class' assembly is referenced by other assemblies that the entry point assembly references; I think there are 2 or 3 levels of assemblies between the class' assembly and the entry point assembly.

I did at one point build a test where an instance of the class was created in the entry point assembly and MemProf did detect that instantiation. Does it have something to do with the class being in an assembly that is several steps removed from the entry point assembly?

Please let me know what else you would like me to provide you.

Patrick

P.S.: I don't mean to be using the term "MemProf" in a derogatory fashion, it's just faster to type.

Andreas Suurkuusk
Posts: 1029
Joined: Wed Mar 02, 2005 7:53 pm

Post by Andreas Suurkuusk » Mon Jul 09, 2007 9:40 am

Yes, it is by design that the Type is listed only after an instance has been created. And since you see the type listed in the "Types" list, it indicates that the profiler has detected the construction of the instance.

Note that only live instances are presented when a heap snapshot is collected. An instance is "live" if it is reachable from any root at the time of the heap snapshot. If the instance didn't exist at the time of the comparison snapshot, it is flagged as "New" as well. A removed instance is an instance that existed in the comparison snaphshot, but that does no longer exist in the primary snapshot.

However, as long as you start the profiled process from the profiler (not attaching), all instance allocations are tracked and you will be able to see the call stack of all instance allocations.

In your case it seems like the created instance becomes garbage collected before the heap snapshot is collected (i.e. it is not reachable from any root). If this is the case, it will not be listed when you filter by "New or removed instances". Rather you should filter by allocations. E.g. double click the type in the Types view, and then select "Allocs/sec" under "Sort stack by". This should show you the call stack of the instance creation.
Best regards,

Andreas Suurkuusk
SciTech Software AB

arkban
Posts: 4
Joined: Fri Jul 06, 2007 5:03 pm

Post by arkban » Mon Jul 09, 2007 1:50 pm

Curious, why does it make a difference whether you attach or versus starting from the profiler?

Yes, the object is created and destroyed before the snapshot is taken. That makes sense that it should only have non-zero values in the "Allocs" and "Bytes" columns. I will try that, thank you.

Patrick

Andreas Suurkuusk
Posts: 1029
Joined: Wed Mar 02, 2005 7:53 pm

Post by Andreas Suurkuusk » Mon Jul 09, 2007 8:39 pm

When you attach to a process, the profiler only investigates the process memory at the time of the snapshot. It does not affect the process in any way. In order to present allocated instances (that are not "live" at the time of the snapshot) the profiler needs to be notified when instances are allocated. This does not happen when attaching, and thus the profiler cannot present allocation information.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests