Jump to content
  • Advertisement
Sign in to follow this  
Geronimo2000

[.net] getting object references

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way to get all the objects that reference another arbitrary object in a C# program? I suppose I'm assuming a strong reference, and not a weak reference. When I run .NET memory profilers, I can see how many objects reference a specific object and which objects those are. I'm looking for similar functionality, just without the profiling environment.

Share this post


Link to post
Share on other sites
Advertisement
I forgot to mention that the exact application I need this for is to determine which objects a System.Attribute is associated with (i.e. which MethodInfo, PropertyInfo, etc. is it associated with when I just have the attribute itself and nothing else).

Thanks to anyone who can help with one or either of my questions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Geronimo2000
I forgot to mention that the exact application I need this for is to determine which objects a System.Attribute is associated with (i.e. which MethodInfo, PropertyInfo, etc. is it associated with when I just have the attribute itself and nothing else).

The common way to do this is to use reflection on all the types you are interested in and enumerating all their fields and properties, checking for the existence of the property on them. This is also known as The Hard Way.

I believe those memory profilers you are talking about go through the unmanaged profiler interface to the .NET runtime.

Share this post


Link to post
Share on other sites
Thanks - I do use that technique when I have the class instances, but I was looking for a way to go backwards when I don't have the class instances.

Anyway, I was afraid that the only way to do this would be some sort of interaction with the .NET runtime, just as you suggested.

Well at least I know it's possible since the profilers do it. Does anyone here know how the profilers interact with the .NET runtime to get object reference information?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!