LoginSignup
34
33

More than 5 years have passed since last update.

メモリリークの対処

Last updated at Posted at 2013-05-23

VC++でメモリーリークが発生しますね。
便利な物で 何番目にどのポインタで何バイトとデータの内容を教えてくれます。

こんなかんじ
Detected memory leaks!
Dumping objects ->
{867} normal block at 0x07A61250, 32 bytes long.
 Data: <XMq             > 58 4D 71 10 00 00 00 00 00 00 00 00 00 00 00 00 
Object dump complete.

でも、一体どこで new したのが原因だかわからないことがあります。
そんなときは、だいたいの場所を推測して
new char[1];

new char[2];
で ソースを挟みます。
推測があっていれば

リーク
Detected memory leaks!
Dumping objects ->
c:\tt.cpp(669) : {3958} normal block at 0x082B9E50, 2 bytes long.
 Data: <  > CD CD 
{867} normal block at 0x07A61250, 32 bytes long.
 Data: <XMq             > 58 4D 71 10 00 00 00 00 00 00 00 00 00 00 00 00 
c:\tt.cpp(668) : {3957} normal block at 0x082B70D8, 1 bytes long.
 Data: < > CD 
Object dump complete.

このように 挟まれて表示されますから、どんどん範囲を狭くしていくと、その場所が特定できます。
原因が特定できないときなどはこのようにやっています。

34
33
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
33