0

I would like to be able to find all the surviving references of some kind of object in any application without having to use an external memory profiler.

My basic idea is that, I just want to be able to list all the alived UserControls inside my app with the name and the object size, this will allow me to spot all the unused controls witch are not really dead :)

After some google researchs I found something that should serve my interests.

icorprofilercallback4::SurvivingReferences

Looks like this is pure C++ and I was not able to find any king of sample.

Did someone already try to do that? I am on the right direction to look for a solution?

Thx for you interest in my question.

valiano
  • 16,433
  • 7
  • 64
  • 79
pix
  • 1,264
  • 19
  • 32

1 Answers1

0

This interface is a part of Microsoft Profiling API. All .NET memory profilers (which you do not want to use) use this API to collect data. For your case you need to obtain all live objects ('survived' is just a subset of them). To obtain object type names you should bind obtained data with assembly metadata and so on.

So, you are on the right way, but this way is very, very, very long. Using one of existent tool is drastically shorter, I would recommend you this way.

Ed Pavlov
  • 2,353
  • 2
  • 19
  • 25
  • I really apreciate that you took some time to answer to my question. I think I found something, it is call ClrMD there is a nice article about it : https://blog.maartenballiauw.be/post/2017/01/03/exploring-.net-managed-heap-with-clrmd.html but I am not sure that I can use it directly in the app that I am monitoring. I will try it :) Any other ideas? – pix Aug 31 '17 at 06:44
  • Guess you can use it from your code. [Here](http://blogs.microsoft.co.il/sasha/2008/05/28/programmatically-generating-a-dump-file/) you can learn how to obtain a memory dump from your code. But be ready that analyzing dump could require significant memory amount and will impact performance of your application. P.S. still interested, why you don't want to use some of existent tool to reach your goals – Ed Pavlov Aug 31 '17 at 09:08
  • I do not want to use external tools because I really want to know how to do it :) personal path of intelectual improvement :) I notice one thing on SO, if this is not a question related to a simple solution, there is not so much emphasis on answers :/ – pix Aug 31 '17 at 09:13
  • For learning purposes both ways are good enough :) The second is easier but the first one will provide more accurate result. Good luck in your investigations! – Ed Pavlov Aug 31 '17 at 11:40
  • @pix May be people do not answer your questions because you do not mark answers as accepted? ;) – Ed Pavlov Sep 26 '17 at 20:15