|
g venu wrote: in main class i created some class objects using NEW operator and in destructor i used delete operator to delete that created objects
When you "new" an object the constructor for the corresponding object gets called and when you "delete" an object the destructor for that object get's called.
But you are saying it doesn't enter the destructor for the corresponding objects when you exit the application. The destructor get's called when you delete the object. Only objects created on stack get's destroyed automatically, the rest should be deleted.
|
|
|
|
|
Post some code, it's much more clear than an explanation. As I understand, you allocate some objects with new:
MyClass* pClass = new MyClass;
And you try to delete the memory inside the destructor ?
MyClass::~MyClass
{
delete this;
}
This will never work. When you create a class with new, its destructor will be called only when you delete the object. You must delete the object outside the destructor.
|
|
|
|
|
i created objects like this and
void mymainDlg::CreateTabWindows()
{
m_phoneDlg = new CGlobe7Phone();
m_phoneDlg->Create(IDD_PHONE,this);
m_TelevisionDlg = new CGlobe7Television();
m_TelevisionDlg->Create(IDD_DIALOG_INTERNET_TELEVISION,this);
m_MessageCenterDlg = new CGlobe7MessageCenter();
m_MessageCenterDlg->Create(IDD_DIALOG_MESSAGECENTER,this);
}
i used destructor like this but it does'nt work and showing memory leaks
mymainDlg::~mymainDlg()
{
delete m_phoneDlg;
delete m_TelevisionDlg;
delete m_MessageCenterDlg;
}
Thank you
venu
|
|
|
|
|
Looks alright to me. Try placing breakpoints in the destructor. The memory leak could be from any of your created dialogs too. Check that any allocated memory in those dialogs is freed when it is destroyed.
|
|
|
|
|
how mymainDlg object is created ? If its created using new, have you deleted it? You need to show that code.
|
|
|
|
|
yes i agree with Weiye Chen The memory leak could be from any of your created dialogs
Are you sure your error is in destructor
|
|
|
|
|
hi prasad,
mymainDlg is created in mymainApp class, i think its not necessary to delete in destructor ?
Thank you
venu
|
|
|
|
|
hi,
you are right ? memeory leaks are shown when my dialogs are created
i,e: in this function
void mymainDlg::CreateTabWindows()
{
m_phoneDlg = new CGlobe7Phone();
m_phoneDlg->Create(IDD_PHONE,this);
m_TelevisionDlg = new CGlobe7Television();
m_TelevisionDlg->Create(IDD_DIALOG_INTERNET_TELEVISION,this);
m_MessageCenterDlg = new CGlobe7MessageCenter();
m_MessageCenterDlg->Create(IDD_DIALOG_MESSAGECENTER,this);
}
but what's wrong in this ??
will u plz tell me
thank you
venu
|
|
|
|
|
hi,
its working when i created separte function
in that function i deleted all the objects which i created
like OnExit Function where my application exits
Thank you all
venu
|
|
|
|
|
g venu wrote: i think its not necessary to delete in destructor
If its created on stack , its d'tor will automatically get called.
But if its created using new, you must use delete.
Can you show code, where main dialog constucted, shown?
|
|
|
|
|
hi prasad,
BOOL mymainApp::InitInstance()
{
// InitCommonControls() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
InitCommonControls();
CWinApp::InitInstance();
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
mymainDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
here is for main dialog which is created
Thank you
venu
|
|
|
|
|
its look perfect to me,too. For just a try,
try creating mymainDlg object on heap, i.e.
code will look like this,
mymainDlg* dlg=new mymainDlg;
m_pMainWnd = dlg;
int nResponse = dlg->DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
delete dlg;
|
|
|
|
|
Another thing you need to take note is that if you call more than 1 time, you will create memory leaks because you didn't check if there's any memory previously allocated to those pointer variables.
|
|
|
|
|
Hi all,
I made an Application in VC++ , as usual it includes StdAfx.h and StdAfx.cpp files .
What I need to do is to eliminate only "StdAfx.cpp" file from my Application.
How can in Achieve it.
Thanks in Advance.
George K Jolly
-- modified at 2:20 Wednesday 16th August, 2006
|
|
|
|
|
georgekjolly wrote: I made an Application in VC++ , as usual it includes StdAfx.h and StdAfx.cpp files .
What I need to do is to eliminate only "StdAfx.cpp" file from my Application.
The main purpose of StdAfx.cpp file is to get the contents of StdAfx.h file compiled, since .h file cannot be compiled. This is done for generating a pch ( PreCompiled Header ) file.
You can disable the use of precompiled files by going to Project Settings --> C/C++ --> PreCompiled Headers --> Not Using Precompiled headers.
As far as your question is considered you can delete StfAfx.cpp but this breaks the purpose of the file.
|
|
|
|
|
Hi Nibu,
ThankYou Very much for ur Answer
George K Jolly
|
|
|
|
|
Press "Enter" key and "ESC" key would dismiss a MFC modal dialog. These two key down events cannot not be directly captured and processed by the modal Dialog as the dialog will be immediately dismissed when user press the two keys.
Is there any way to avoid this happening? Is there any way to modify this behaviour of MFC model dialog?
|
|
|
|
|
|
Hi, Mike. Did you get my email ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
You need to override OnOK and OnCancel in your dialog
|
|
|
|
|
Hi all,
in my project i am having a docking window on with class CDocBuild
class CDocBuild:public CSizingDocBar
now i want to create a tab control in this docking window.
in which there will can be build result window,watch window etc
something like vc6.0 build window.
so currently i am adding CTabCtrl m_wndTabCtrl as a public member in this class.
and then doing InsertItem to create new tabs and associating imagelist with it.
but InsertItem returns 0 based index of the new tab. it doesnot give handle to the newly added tab. so that's why i am not able to create new child window in this page.
so i want to create child window's in this new pages such as edit box list view etc. so How should i proceed?
and one more question as i said i am adding public member as m_wndTabCtrl which is object of CTabCtrl but i am confused whether i should derive a class from CTabCtrl and then make it's object as m_wndTabCtrl??
class BuildTab: public CTabCtrl
{
};
BuildTab m_wndTabCtl;//in docking window
What advantage this method gives??
Thanks and regards
Harshal
|
|
|
|
|
Hi,
I had developed a client program which uses CAsyncSocket... I used to create the socket as m_mySocket.Create(0,SOCK_STREAM) where m_mysocket is an object of the class derived from CAsyncSocket.
When this program runs on "Microsoft Vista" operating system which uses IPV6 ...it is throwing an error "10047(An address incompatible with the requested protocol was used. )".
Can anyone tell me how to solve it?? I am very new to IPV6.
Thanks and Regards.
Pappu Kumar
|
|
|
|
|
I downloaded this sample project:
http://www.codeproject.com/dialog/wizard2000.asp
and added a menu bar with File/New, Open and Save. I also added CDoc, but
I cant get it to serialize any data, not even call the serialize functions.
Is it possible to serialize data using this design? If so, how would I
go about. A simple project that serializes just a little data would guide
me significantly.
I thought about creating an SDI application with many views that mimics
this Wizard look, but Im hoping I can adjust the Wizard.
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle Brina
|
|
|
|
|
Here is the code the get image and save as the computer!!!However, sometimes the image did not get all bytes. (e.g image size= 85,687 bytes but it only get 75,776 bytes) It is sometimes only.....I don't know what the problem is?
Can anyone help?
<br />
UINT nBytesRead;<br />
TCHAR szBuf[CHUNK_SIZE] = {0};<br />
CFile objThumbFile;<br />
CHttpFile* pHttpFile = <br />
pHttpConnection->OpenRequest<br />
(_T("GET"), <br />
_T(strPhotoLink), <br />
NULL, 1, NULL, NULL, <br />
INTERNET_FLAG_KEEP_CONNECTION |<br />
INTERNET_FLAG_EXISTING_CONNECT |<br />
INTERNET_FLAG_DONT_CACHE |<br />
INTERNET_FLAG_RELOAD);<br />
<br />
CString strResponse;<br />
if(!objThumbFile.Open(strOutputFileName, CFile::modeCreate | CFile::modeWrite, NULL))<br />
return false;<br />
do<br />
{<br />
nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE);<br />
strResponse += szBuf;<br />
objThumbFile.Write(szBuf, CHUNK_SIZE);<br />
i++;<br />
}while(nBytesRead > 0);<br />
<br />
objThumbFile.Close();
|
|
|
|