指针和删除的动态数组(与AppVerifier崩溃) [英] Dynamic array of pointer and deletion (Crash with AppVerifier)

查看:106
本文介绍了指针和删除的动态数组(与AppVerifier崩溃)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有点奇怪的行为。我有一个CDialog派生对象(COptionsWizard:public CDialog),它有一个派生CFormView对象的动态数组(COptionsWizardPage:public CFormView)。所以成员变量是这样的:
$

 COptionsWizardPage ** m_pSteps; 


在构造函数中我初始化对象如下: />

 m_StepCount = 2; 

m_pSteps = new COptionsWizardPage * [m_StepCount];
$
m_pSteps [0] = new COptionsGeneral(this ); $
m_pSteps [1] =新的COptionsColor(this);


稍后我创建(...)视图并将它们一个接一个地显示在我的对话框中(这样我就得到了一个像用户可以在视图之间切换的行为标签)。

在我的对话框的析构函数中删除对象: delete m_pSteps [i];
delete [] m_pSteps;


这不是正确的做法吗?它在调试和发布时都能正常工作。没有任何问题。

现在出现了一件奇怪的事情。我使用AppVerifier测试了我的应用程序(我在WM6仿真器上直接使用了WM5版本的ARM,因为我没有让它在dektop的Vista x64上使用我的DeviceCentral)。当AppVerifier测试时,每当我关闭我的COptionsWizard-Dialog时,我会在删除第一个m_pSteps时在dectructor中遇到访问冲突。如果我从析构函数中删除for循环并且只有"delete [] m_pSteps",则AppVerifier运行时应用程序不会再崩溃。事实上,AppVerifier的结果日志显示FEWER现在泄漏。

我错过了什么吗?我想如果我删除了我的COptionWizardPage的for循环删除,我应该导致更多的内存泄漏!?!?!?

任何人的想法?

BTW:析构函数我的COptionsWizardPage派生的都是空的。

感谢
Maik

解决方案

您的所有对话框都是模态对话框?你展示了new和delete,但没有显示DoModal或Create - 你创建这些窗口的方式。


当你在析构函数中删除对话框时,你实际上是在破坏窗口。


Hi,
I got a little strange behaviour here. I have a CDialog derivied object (COptionsWizard : public CDialog) that has a dynamic array of derived CFormView objects (COptionsWizardPage : public CFormView). So the member variable is like this:

COptionsWizardPage** m_pSteps;

In the constructor I initialize the objects like this:

	m_StepCount = 2;
m_pSteps = new COptionsWizardPage*[m_StepCount];
m_pSteps[0] = new COptionsGeneral(this);
m_pSteps[1] = new COptionsColor(this);

Later I Create(...) the views and display them embedded on my dialog one after another (that way I got a tab like behavior the user can switch between the views).

In the destructor of of my dialog I delete the objects:

	for (int i=0; i<m_StepCount; i++)
		delete m_pSteps[i];
	delete[] m_pSteps;

Isn't this is the right way to do? It works fine in debug and release without any problems.

The strange thing comes now. I tested my application using AppVerifier (I used the WM5 version for ARM directly on the WM6 emulator, because I didn't get it to work with my DeviceCentral on Vista x64 from the dektop). While AppVerifier tests, everytime I close my COptionsWizard-Dialog I get a crash with an access violation in the dectructor at the deletion of the first m_pSteps. If I remove the for-loop from the destructor and only have "delete[] m_pSteps", the app does not crash anymore while AppVerifier runs. In fact the result log of AppVerifier show FEWER leaks now.

Am I missing something? I think if I remove the for-loop deletion of my COptionWizardPage I should result in more memory leaks!?!?!?

Any ideas anyone?

BTW: The destructors of my COptionsWizardPage derived are all empty.

Thanks
 Maik

解决方案

All your dialogs are modal dialogs? You showed new and delete, but didn't show DoModal or Create - the way you create these windows.

When you delete your dialogs in destructor, you actually destroying the windows.


这篇关于指针和删除的动态数组(与AppVerifier崩溃)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆