vinnzcrafts
19th March 2014, 11:28
Hello, I have some code I wanted to make sure I have no memory leaks in it so I ran it on my mac and opened activity monitor to see how much memory it was using, then I kept opening new windows(Editor class mentioned in code below) and closing it, and the memory usage increased when I opened them and didn't decrease as I closed. I tried the same thing in top using terminal to get the same result. Is it some lack of knowledge on my behalf on how activity monitor, top and even memory usage works? is it normal? or is there a leak in the code below
P.S. The Editor class allocates nothing dynamically (at least not more than child widgets and variables that were suppose to be disposed after the class is deleted right? ).
add_editor (when a new window is opened):
void MainControl::add_editor(int mode)
{
int i=0;
QPointer<Editor> *editor_aux=new QPointer<Editor> [editor_n+1];
while(i<editor_n)
{
editor_aux[i]=editor_array[i];
i++;
}
editor_aux[i]=new Editor(i,mode);
set_editor_conenctions(editor_aux[i]);
delete[] editor_array;
editor_array=editor_aux;
editor_n++;
if(editor_array[i]->start_response==2)
{
del_editor(editor_array[i]->id);
}
}
del_editor (when the window is closed):
void MainControl::del_editor(int id_arg)
{
if(editor_n>1)
{
int i=0;
int a=0;
QPointer<Editor> *editor_aux=new QPointer<Editor>[editor_n-1];
while(i<editor_n)
{
if(editor_array[i]->id==id_arg)
{
unset_editor_conenctions(editor_array[i]);
delete editor_array[i];
}else{
editor_aux[a]=editor_array[i];
a++;
}
i++;
}
delete[] editor_array;
editor_array=editor_aux;
editor_n--;
}
//This below is not needed because when the last window is closed the program closes
/*
if(editor_n==1){
editor_n=0;
delete editor_array[0];
}
*/
}
P.S. The Editor class allocates nothing dynamically (at least not more than child widgets and variables that were suppose to be disposed after the class is deleted right? ).
add_editor (when a new window is opened):
void MainControl::add_editor(int mode)
{
int i=0;
QPointer<Editor> *editor_aux=new QPointer<Editor> [editor_n+1];
while(i<editor_n)
{
editor_aux[i]=editor_array[i];
i++;
}
editor_aux[i]=new Editor(i,mode);
set_editor_conenctions(editor_aux[i]);
delete[] editor_array;
editor_array=editor_aux;
editor_n++;
if(editor_array[i]->start_response==2)
{
del_editor(editor_array[i]->id);
}
}
del_editor (when the window is closed):
void MainControl::del_editor(int id_arg)
{
if(editor_n>1)
{
int i=0;
int a=0;
QPointer<Editor> *editor_aux=new QPointer<Editor>[editor_n-1];
while(i<editor_n)
{
if(editor_array[i]->id==id_arg)
{
unset_editor_conenctions(editor_array[i]);
delete editor_array[i];
}else{
editor_aux[a]=editor_array[i];
a++;
}
i++;
}
delete[] editor_array;
editor_array=editor_aux;
editor_n--;
}
//This below is not needed because when the last window is closed the program closes
/*
if(editor_n==1){
editor_n=0;
delete editor_array[0];
}
*/
}