dlete pointer.
-
In my case the above mentioned 4 cases will not be satisfied. Actual reason is any other.:-> And also as per ur comments int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.:confused: yours faithfully ajeeshcv
Ajeesh c v wrote:
int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.
he doesn't say it is the things to do... the cases enumerated are possible causes for a crash when deleting a pointer X|
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
In my case the above mentioned 4 cases will not be satisfied. Actual reason is any other.:-> And also as per ur comments int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.:confused: yours faithfully ajeeshcv
Ajeesh c v wrote:
how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.
That's probably your problem. When you do this:
int* pTest;
if (pTest)
delete pTest;You will have an excpetion because you try to delete memory that is unitianalized (you can only delete memory that has been allocated with new). So, to be sure not to delete this 'unexistant' memory, assign NULL to the pointer. This is safe.
Cédric Moonen Software developer
Charting control -
In my case the above mentioned 4 cases will not be satisfied. Actual reason is any other.:-> And also as per ur comments int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.:confused: yours faithfully ajeeshcv
According to documentation (http://msdn2.microsoft.com/en-us/library/h6227113.aspx[^]), “You can [...] use delete on a pointer with the value 0”. Therefore instead of
if( p != NULL ) { delete p; p = NULL; }
you can use
delete p; p = NULL;
However, this does not belong to original topic. I think you should put a breakpoint at the line where your block of memory is allocated and the pointer is assigned. Then investigate the pointer’s value and the content of the memory block. Then stop on the line where the pointer is deleted. Check if the pointer contains right address value. Try to use step-be-step execution during deletion. Perhaps the pointer points to an object having destructor, and the problem is within this function.
-
Ajeesh c v wrote:
exception is occuring.
DAMNNNNN !!! WHICHHHH ????? if you don't provide some descriptions of your error case, how can one help you ?? :~ :mad:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
ok... I think the problem is occuring due to this reason. am initializing the pointer from thread...adn try to delete it from another thread.. if there is any chance of occuring exception???? Please help me... yours faithfully ajeeshcv
as far as you don't answer my questions, i don't help you furthermore. :zzz:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
That's a very clear description of the problem :~ The solution is: you did something wrong.
Cédric Moonen Software developer
Charting control -
ok... I think the problem is occuring due to this reason. am initializing the pointer from thread...adn try to delete it from another thread.. if there is any chance of occuring exception???? Please help me... yours faithfully ajeeshcv
I think this causes problems if your project’s configuration does not allow multi-threading. You should open the project’s properties dialog and be sure that the C/C++ --> Code Generation --> Runtime Library option contains a right value related to multi-threading. Then rebuild the application.
-
Can you show how to use pointer and how to declare pointer_**
**_
whitesky
-
I think this causes problems if your project’s configuration does not allow multi-threading. You should open the project’s properties dialog and be sure that the C/C++ --> Code Generation --> Runtime Library option contains a right value related to multi-threading. Then rebuild the application.
-
The pointer is of a dialog. Initialization: CMyDialog* pMyDialog; pMyDialog = new CMyDialog; pMyDialog->EndDialog(0); if(pMyDialog) { delete pMyDialog; pMyDialog = 0; } yours faithfully ajeeshcv
im not sure your problem is this but how to create dialog? and if you run your code i think you get a error in pMyDialog->EndDialog(0); now try this and send me if you have a error
CMyDialog* pMyDialog; pMyDialog = new CMyDialog; pMyDialog->Create(IDD_TEST);//id from dialog pMyDialog->EndDialog(0); delete pMyDialog ; pMyDialog = 0;
_**
**_
whitesky
-
ok... I think the problem is occuring due to this reason. am initializing the pointer from thread...adn try to delete it from another thread.. if there is any chance of occuring exception???? Please help me... yours faithfully ajeeshcv
Ajeesh c v wrote:
am initializing the pointer from thread...adn try to delete it from another thread
May one thread still be accessing the memory you just deleted? Maybe using smart-pointers (like those from boost.org)[^]can help you? Or at least an object which can delete itself via a member function?
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.