Click here to Skip to main content
12,350,035 members (24,688 online)
Click here to Skip to main content

Stats

111.1K views
2.1K downloads
235 bookmarked
Posted

Finding Undisposed Objects

, 13 Aug 2009 Ms-PL
An application to find undisposed objects in your .NET application.
#include "StdAfx.h"
#include "FinalizerRunLogger.h"
#include <sstream>

FinalizerRunLogger::FinalizerRunLogger(const ObjectTracker &objectTracker)
: m_ObjectTracker(objectTracker)

{
	// outputWriter.open("E:\\Test.log");
}

FinalizerRunLogger::~FinalizerRunLogger(void)
{
}

STDMETHODIMP FinalizerRunLogger::Initialize(const std::wstring &logFilePath)
{
	outputWriter.open(logFilePath.c_str());
	return S_OK;
}

STDMETHODIMP FinalizerRunLogger::FinalizeableObjectQueued(DWORD finalizerFlags, ObjectID objectID)
{
	ObjectCreationSnapshot snapshot;

	if (FAILED(m_ObjectTracker.GetCreationSnapshot(objectID, &snapshot)))
		return E_FAIL;

	std::wostringstream fullStackAsText;
	std::vector<std::wstring> stack = snapshot.stack;

	for (std::vector<std::wstring>::iterator iter = stack.begin(); iter != stack.end(); ++iter)
	{
		fullStackAsText << *iter << std::endl;
	}

	outputWriter
		<< objectID << std::endl
		<< snapshot.clrClass.fullTypeName << std::endl 
		<< fullStackAsText.str().c_str() << std::endl 
		<< std::endl;
	outputWriter.flush();

	return S_OK;
}

STDMETHODIMP FinalizerRunLogger::Shutdown()
{
	outputWriter.close();
	return S_OK;
}

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.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 13 Aug 2009
Article Copyright 2009 by S. Senthil Kumar
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid