Click here to Skip to main content
15,891,136 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: constructor for POD types? Pin
George_George12-Mar-08 19:35
George_George12-Mar-08 19:35 
GeneralRe: constructor for POD types? Pin
Michael Dunn16-Mar-08 16:08
sitebuilderMichael Dunn16-Mar-08 16:08 
GeneralRe: constructor for POD types? Pin
George_George16-Mar-08 16:31
George_George16-Mar-08 16:31 
GeneralRe: constructor for POD types? Pin
Michael Dunn16-Mar-08 16:38
sitebuilderMichael Dunn16-Mar-08 16:38 
GeneralRe: constructor for POD types? Pin
George_George16-Mar-08 16:42
George_George16-Mar-08 16:42 
GeneralRe: constructor for POD types? Pin
Michael Dunn16-Mar-08 16:57
sitebuilderMichael Dunn16-Mar-08 16:57 
GeneralRe: constructor for POD types? Pin
George_George16-Mar-08 22:50
George_George16-Mar-08 22:50 
Questionresource leak in this case? Pin
George_George12-Mar-08 14:54
George_George12-Mar-08 14:54 
Hello everyone,


Even if I have tested with MSVC 2008 that no resource leak, I want to confirm with you whether it is good code to maintain resource and avoid resource leak. Also whether the code is dependent on some non-Spec regulated points, e.g. MSVC 2008 specific things. Smile | :)

The design pattern is, embed a sub-object into another object (e.g. embed Goo object g into Foo object), but in destructor of Foo, destructor of its sub-object (e.g. Goo object g) is not called explicitly.

I have tested destructor of Goo object g will be called in MSVC 2008, but I am not sure whether we could rely on this -- when object goes out of scope, its sub-object also goes out of scope and destructor always gets called?

#include <iostream>

using namespace std;

class Goo {
public:
	Goo()
	{
		cout << "constructing Goo" << endl;
	}
	virtual ~Goo()
	{
		cout << "destructing Goo " << endl;
	}
};

class Foo {
public:
	Goo g;
	
	Foo (Goo _g) : g (_g)
	{
		cout << "constructing Foo " << endl;
	}

	virtual ~Foo()
	{
		cout << "destructing Foo " << endl;
	}
};

int func()
{
	Goo g;
	Foo f (g);

	return 0;
}

int main()
{
	func();
	return 0;
}



thanks in advance,
George
AnswerRe: resource leak in this case? Pin
Eytukan12-Mar-08 15:35
Eytukan12-Mar-08 15:35 
GeneralRe: resource leak in this case? Pin
George_George12-Mar-08 16:15
George_George12-Mar-08 16:15 
AnswerRe: resource leak in this case? Pin
Rajkumar R12-Mar-08 21:36
Rajkumar R12-Mar-08 21:36 
GeneralRe: resource leak in this case? Pin
George_George12-Mar-08 21:43
George_George12-Mar-08 21:43 
QuestionRe: resource leak in this case? Pin
Rajkumar R12-Mar-08 21:50
Rajkumar R12-Mar-08 21:50 
GeneralRe: resource leak in this case? Pin
George_George12-Mar-08 21:53
George_George12-Mar-08 21:53 
AnswerRe: resource leak in this case? Pin
KarstenK12-Mar-08 22:11
mveKarstenK12-Mar-08 22:11 
GeneralRe: resource leak in this case? Pin
George_George12-Mar-08 22:31
George_George12-Mar-08 22:31 
AnswerRe: resource leak in this case? Pin
Maxwell Chen12-Mar-08 22:15
Maxwell Chen12-Mar-08 22:15 
GeneralRe: resource leak in this case? Pin
George_George12-Mar-08 22:34
George_George12-Mar-08 22:34 
AnswerRe: resource leak in this case? Pin
Maxwell Chen12-Mar-08 22:39
Maxwell Chen12-Mar-08 22:39 
GeneralRe: resource leak in this case? Pin
George_George12-Mar-08 22:51
George_George12-Mar-08 22:51 
AnswerRe: resource leak in this case? Pin
Maxwell Chen12-Mar-08 22:54
Maxwell Chen12-Mar-08 22:54 
GeneralRe: resource leak in this case? Pin
George_George12-Mar-08 23:01
George_George12-Mar-08 23:01 
AnswerRe: resource leak in this case? [modified] Pin
Maxwell Chen12-Mar-08 23:11
Maxwell Chen12-Mar-08 23:11 
GeneralRe: resource leak in this case? Pin
George_George13-Mar-08 0:52
George_George13-Mar-08 0:52 
QuestionRe: resource leak in this case? Pin
Maxwell Chen13-Mar-08 8:47
Maxwell Chen13-Mar-08 8:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.