求救:为什么会内存泄漏?

lens23 2004-05-02 11:11:52
在下新手一个,我写的一个基于对话框的程序,编译都通过了,但是一运行,立刻就占用9X%的CPU,连对话框都没弹出来,后来设置断点跟踪到.../MFC/SRC/DLGCORE.cpp文件中
// create modeless dialog
AfxHookWindowCreate(this);
--> hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate,
pParentWnd->GetSafeHwnd(), AfxDlgProc);
行时出现错误
弹出Debug Library对话框
dlgdata.cpp
line 43
有错
'关闭'后下面的Debug 窗口提示如下,告诉Detect memory leak?这是为什么呢
我用的链表和节点头文件是基于Template的,回合这个有关系吗?

Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded symbols for 'D:\WINDOWS\system32\MFC42D.DLL'
Loaded symbols for 'D:\WINDOWS\system32\MSVCRTD.DLL'
Loaded 'D:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded symbols for 'D:\WINDOWS\system32\MFCO42D.DLL'
Loaded symbols for 'D:\WINDOWS\system32\MFCN42D.DLL'
Loaded symbols for 'D:\WINDOWS\system32\MSVCIRTD.DLL'
Loaded 'D:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\lpk.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\mfc42loc.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\wsock32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\ws2_32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\ws2help.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\comctl32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\MSCTF.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\nview.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\SHLWAPI.DLL', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\shell32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\psapi.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\ole32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\powrprof.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\version.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\olepro32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\oleaut32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\ddraw.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\dciman32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.10.0_x-ww_f7fb5805\comctl32.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\MSCTFIME.IME', no matching symbolic information found.
Error: no data exchange control with ID 0x03ED.
Loaded 'D:\WINDOWS\system32\nviewimg.dll', no matching symbolic information found.
Loaded 'D:\WINDOWS\system32\MSIMTF.dll', no matching symbolic information found.
Detected memory leaks!
Dumping objects ->
strcore.cpp(118) : {63} normal block at 0x00421720, 45 bytes long.
Data: < > 01 00 00 00 04 00 00 00 20 00 00 00 CB CE CC E5
{62} normal block at 0x00421780, 32 bytes long.
Data: < > FF FF FF FF CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
The thread 0x11C has exited with code 3 (0x3).
The program 'H:\MFC\Debug\MFC.exe' has exited with code 3 (0x3).
...全文
54 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
GameWeaverDummy 2004-05-03
帮你顶
回复
lens23 2004-05-03
struct Deal
{
char mode; // mode buy or sell
float money; // money accout
long amount; // dealing amount
};

本来是在console下运行的,现在开始学MFC,于是拿出来练一下。
看来差得还很远哪
回复
lens23 2004-05-03

BOOL CMFCDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
//----------------------------我加的代码--------------------------------
//initilize the variable
// declare lists for buy and sell
LinkedList<Deal> *B=new LinkedList<Deal>;
LinkedList<Deal> *S=new LinkedList<Deal>;
//LinkedList<Deal> B,S;
Deal *M=new Deal;
Deal *bf=new Deal;
Deal *sf=new Deal;
//Deal M,bf,sf;
int i=0;
// sort the List when there is a new come in.
while(M->mode!='o' && M->mode!='O')
{
Input(*M); // input information
if(M->mode=='B' || M->mode=='b' )
{
if (B->currPtr==NULL) B->InsertFront(*M);
else B->InsertAfter(*M);
Sort(*B); // sort the list Buy
}
if(M->mode=='S' || M->mode=='s' )
{
if (S->currPtr==NULL) S->InsertFront(*M);
else S->InsertAfter(*M);
Sort(*S); // sort the list Sell
}
cout<<" input succussfull!"<<endl;
// goto Handle(B,S) if neccesary
if (!S->ListEmpty() && !B->ListEmpty() ) //garentee the top of the two lists is not empty
{
bf=&(B->ListFront());
sf=&(S->ListFront());
if (bf->money>=sf->money) Handle(*B,*S); // go to handle the deal
} // if level
} //while level
delete S,B,M,bf,sf;
//----------------------------- 我加的代码写完了 ------------------------------
return TRUE; // return TRUE unless you set the focus to a control
}
回复
lens23 2004-05-03
恩,大虾们分析的对呀,呵呵,原先的还是基于过程的,没有利用消息机制做出反应是不对的。重新来过吧,多谢了。

继续努力!
继续努力!
继续努力!
回复
菜牛 2004-05-03
LinkedList<Deal> *B=new LinkedList<Deal>;
LinkedList<Deal> *S=new LinkedList<Deal>;
不知道你的这个LinkedList是什么东东,假设是一个链表模板类吧,你的程序干什么?在初始化对话框的时候做了一大堆操作,最后声明的变量全删除了,什么也不留下,就算没有错误,想得到什么结果?
最后,delete链表的时候,链表包含的数据能够在他的析构函数中得到释放吗?
那个Input()又是什么东西?Handle()又是什么东西?感觉你是把console下的代码直接移植过来,没有搞清楚Windows的运行机制。
回复
anothervip 2004-05-02
没遇到过,看看句柄和指针是否有效。

你的对话框中都有什么成员?
回复
菜牛 2004-05-02
代码。
回复
subtop 2004-05-02
把代码帖出来看看啊
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-05-02 11:11
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……