Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / strange memory problems on quitting

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. strange memory problems on quitting
#4227
Posted by: 2004-05-26 04:33:18
Hi all :)

I don't understand nothing : sometimes when I quit my basic wxWidgets app, it exits with a memory error! On windows and linux, it's the same (with the same source of course).

Sometimes if I add a new control in my interface, I have this problem, if I remove it, no problem. I tried to make a clean exit by making an "onclose" event and a Destroy() call in it, but it doesn't change anything, the same problem appears sometimes.

What do I do wrong? Any idea? Is there a special way to quit wxWidgets app ? Any particular cleanup code to put somewhere? I thougt every graphical control is deleted automatically by wxWidgets and the coder just have to delete its own non visual pointers.

Thanks for any answer.
Message2. Re: strange memory problems on quitting
#4235
Posted by: upCASE 2004-05-26 15:00:40
Hi!
True, normally the pointers should be deleted automatically.
Could you tell us what version of gcc/wxWidgets you're using and maybe post a little code snippet that causes a problem like you described it?
Have you tried debbuging the app to see what causes the error?
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: strange memory problems on quitting
#4253
Posted by: 2004-05-27 05:13:13
The problem occurs at random operations, for example here's my code by now:

in the frame constructor, at the end, we have this :
config = new wxFileConfig("", "", "dexianet.conf", "", wxCONFIG_USE_LOCAL_FILE |
      wxCONFIG_USE_RELATIVE_PATH | wxCONFIG_USE_NO_ESCAPE_CHARACTERS);
  
   notebook = new wxNotebook((wxWindow*)this, -1);
   TabGeneral *general_tab = new TabGeneral((wxWindow*)notebook, config);
   notebook->AddPage(general_tab, _T("General"), true);
   TabConfigure *configure_tab = new TabConfigure((wxWindow*)notebook, config);
   notebook->AddPage(configure_tab, _T("Configure"));

I have defined a onclose event:
EVT_CLOSE(MainWindow::OnClose)

and the function:
void MainWindow::OnClose(wxCloseEvent &e)
{
   if (config != NULL) delete config;
   Destroy();
}

If I remove the config class, it works. If I remove the destructor, all work well, the config file (used later in the code work very well), but when I quit the application... baaaaaangs memory error --> crash. :/

Here it's with a wxFileConfig object, but it occured sometimes with objects as simple as wxButton!! It I commented the objected declaration, it worked...

In the past I defined destructors of all my class, just in case. But they were empty. I thought the error came from there, and I removed all my destructors. It worked... until I added this new wxFileConfig in my program...

Thanks for any help.
Message4. Re: strange memory problems on quitting
#4254
Posted by: 2004-05-27 05:16:07
I must say that "config" is of course properly declared (as a wxFileConfig pointer) in the private scope of my frame class.

Thanks again.
Message5. Re: strange memory problems on quitting
#4315
Posted by: 2004-06-02 18:41:06
I've got the same kind of problem:

I've got a wxFrame which contains a wxScrolledWindow

I can't quit (it freezes) and its behavior is somewhat bizzare.

But if I remove the wxScrolledWindow, everything works fine.

Any ideas? (I tried several methods to destroy the scrollwnd on exit)

Thanks!
Message6. Re: strange memory problems on quitting
#4460
Posted by: 2004-06-15 04:43:07
Euh... my program works now... The only thing I changed is remove some ";" I wrote after some macro declaration (that's a mistake I know but the GCC compiler never complained about this, under windows neither under linux). I also put the DECLARE_EVENT_TABLE() at the end of the classes, not within a dedicated protected block, like I did before.

I don't know why now it works but it works... Is it possible that these little mistakes made my program crash before I corrected it???

Thanks :)
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Mon 2021-4-12  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0