Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Finding Undisposed Objects

, 13 Aug 2009
An application to find undisposed objects in your .NET application.
#pragma once

#include "TypeTracker.h"
#include <set>

struct ObjectCreationSnapshot
{
	ObjectID objectId;
	ClassID classId;
	CLRClass clrClass;
	std::vector<std::wstring> stack;
};

class ObjectTracker
{
public:
	ObjectTracker(TypeTracker &typeTracker) : m_TypeTracker(typeTracker){}
	~ObjectTracker(void);
	void SetTypeFilter(const std::vector<std::wstring> &typeFilters);

	void Initialize(CComPtr<ICorProfilerInfo2> pCorProfilerInfo);
	STDMETHODIMP ObjectAllocated(ObjectID objectId, ClassID classId);
	STDMETHODIMP SurvivingReferences(ULONG cSurvivingObjectIDRanges,
		ObjectID objectIDRangeStart[  ],
		ULONG cObjectIDRangeLength[  ]);

	STDMETHODIMP MovedReferences( ULONG cMovedObjectIDRanges,
		ObjectID oldObjectIDRangeStart[  ],
		ObjectID newObjectIDRangeStart[  ],
		ULONG cObjectIDRangeLength[  ]);

	HRESULT GetCreationSnapshot(ObjectID objectId, ObjectCreationSnapshot *creationSnapshot) const;

private:
	static void HandleClassLoad(const CLRClass &classLoad, void *data);
	bool PassesFilter(const std::wstring &typeName);

	CComPtr<ICorProfilerInfo2> m_pCorProfilerInfo;
	TypeTracker &m_TypeTracker;

	typedef std::map<ObjectID, ObjectCreationSnapshot>::const_iterator OBJECT_CREATIONS_ITERATOR;
	std::map<ObjectID, ObjectCreationSnapshot> m_resolvedObjectCreations;
	
	typedef std::map<ClassID, ObjectCreationSnapshot>::const_iterator UNRESOLVED_OBJECT_CREATIONS_ITERATOR;
	std::map<ClassID, ObjectCreationSnapshot> m_unResolvedObjectCreations;
	
	std::vector<std::string>::const_iterator TYPE_FILTER_ITERATOR;
	std::set<std::wstring> m_TypeFilters;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

S. Senthil Kumar
Software Developer Atmel R&D India Pvt. Ltd.
India India
I'm a 27 yrs old developer working with Atmel R&D India Pvt. Ltd., Chennai. I'm currently working in C# and C++, but I've done some Java programming as well. I was a Microsoft MVP in Visual C# from 2007 to 2009.
 
You can read My Blog here. I've also done some open source software - please visit my website to know more.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 13 Aug 2009
Article Copyright 2009 by S. Senthil Kumar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid