this is my code :
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define JUMLAH 1000000
#define ISI 100
typedef struct _dodol
{
char *string;
} dodol;
void testing(void)
{
dodol **abc = (dodol**)malloc( JUMLAH * sizeof(dodol*) );
memset(abc, 0, JUMLAH * sizeof(dodol*));
int i;
char a[10];
for(i=0; i<JUMLAH; i++) {
abc[i] = (dodol*)malloc(sizeof(dodol));
abc[i]->string = strdup("HALLLLLLLLLLOOOOOOOOOOOO");
}
for(i=0; i<JUMLAH; i++) {
free( abc[i]->string );
free( abc[i] );
}
free(abc);
}
int main()
{
int i, j;
char a[10];
printf("ready to insert\n");
scanf("%s",a);
j=1;
for(i=0; i<j; i++)
testing();
printf("done free\n");
scanf("%s",a);
return 0;
}
If i run that code, it will be memory leak.
But if i change j>1 (testing() running more than 1 time), the memory is cooled down.
Whats wrong? >.<