Sun workshop memory monitor does not detect all memory leak

Sun workshop memory monitor does not detect all memory leak

Post by __jakal_ » Wed, 14 Apr 2004 17:40:55



Cud somebody tell me wat is happening???
I am checking if I can use Sun WorkShop Memory Monitor as a substitute for
Rational purify
but this simple leak is not detected.

#include <iostream.h>
int main()
{
int *name ;
name = new int[10];                                 <-------this is not
detected as leak
cout<< "name is "<<name[0] <<endl;
delete [] name;
return 0;

Quote:}

 On the other hand if i allocate memory in a loop like this it is detected
as a leak

#include <iostream.h>
int main()
{
int *name ;
/for (int i=0; i<3 ; i++)
    name = new int[10];                                 <-------this is
detected as leak
cout<< "name is "<<name[0] <<endl;
delete [] name;
return 0;

Quote:}

Is it safe to go ahead and use Sun WorkShop Memory Monitor instead of
purify?
 
 
 

Sun workshop memory monitor does not detect all memory leak

Post by Paul Floy » Thu, 15 Apr 2004 05:33:05



> Cud somebody tell me wat is happening???
> I am checking if I can use Sun WorkShop Memory Monitor as a substitute for
> Rational purify
> but this simple leak is not detected.

> #include <iostream.h>
> int main()
> {
> int *name ;
> name = new int[10];                                 <-------this is not
> detected as leak
> cout<< "name is "<<name[0] <<endl;

Isn't this an uninitialized memory read?

Quote:> delete [] name;

Doesn't this free the memory?

I can't verify this as I'm using my PC and the x86 version of dbx
doesn't support access checking.

A bientot
Paul
--
Paul Floyd                 http://paulf.free.fr (for what it's worth)
Surgery: ennobled Gerald.

 
 
 

Sun workshop memory monitor does not detect all memory leak

Post by Frank Langelag » Thu, 15 Apr 2004 06:02:52



> Cud somebody tell me wat is happening???
> I am checking if I can use Sun WorkShop Memory Monitor as a substitute for
> Rational purify
> but this simple leak is not detected.

> #include <iostream.h>
> int main()
> {
> int *name ;
> name = new int[10];                                 <-------this is not
> detected as leak

because it is no leak AFAIK. You declare a int pointer with name name
and don't initialize it. Then you assign a vlaue to this pointer.
Quote:> cout<< "name is "<<name[0] <<endl;
> delete [] name;
> return 0;
> }

>  On the other hand if i allocate memory in a loop like this it is detected
> as a leak

> #include <iostream.h>
> int main()
> {
> int *name ;
> for (int i=0; i<3 ; i++)
>     name = new int[10];                                 <-------this is
> detected as leak

Here you assign a value to the pointer three times. So the first two
allocated int arrays get unaccessable. This is a leak.
Quote:> cout<< "name is "<<name[0] <<endl;
> delete [] name;
> return 0;
> }

> Is it safe to go ahead and use Sun WorkShop Memory Monitor instead of
> purify?

Don't know. I've used purify with good results. No experiences with Sun
WorkShop Memory Monitor.