|
[Sponsors] |
March 14, 2016, 21:54 |
Crashes and suspicious memory management
|
#1 |
New Member
Data C
Join Date: Feb 2016
Posts: 8
Rep Power: 10 |
During the destruction of many classes, you can see something like this:
if (MG_PreSmooth!=NULL) delete [] MG_PreSmooth; But the delete [] MG_PreSmooth also happens somewhere else in the class before the destruction. I guess the author may assume delete [] MG_PreSmooth will make the MG_PreSmooth become NULL. So, the destruction could skip it. But the reality is that delete [] will never make a pointer NULL. So, the destruction will attempt to delete [] MG_PreSmooth again and it may destroy some other data. The "new" and "delete" should be avoided as much as possible to favor the smart pointer management such as std::unique_ptr. Right now, I have a lot of delete[] related crashes. |
|
May 24, 2016, 22:39 |
|
#2 | |
Senior Member
Heather Kline
Join Date: Jun 2013
Posts: 309
Rep Power: 13 |
Quote:
|
||
|
|