Hi all,
I have a function which calls itself 10 times a second. I am using QTimer for repeat calls.
void DisplayClass::UpdateGuiWithData()
{
//miscellaneous code which is validated
SingletonObjectAsThread::instance()->UpdateFromGuiToExternalHardware(ClassOjbectArray,var1,var2);
QTimer::singleShot(100,this,SLOT(UpdateGuiWithData()));
}
Class A_ComposingClass_B_Object
{
//boolean and enum variables
B ArrayOf_B_Objects[16];
}
Class B
{
//boolean and enum vairables
}
class DisplayClass
{
//variables that are not a concern here
UpdateGuiWithData();
A ArrayOfObject_A[4];
};
Class SingletonAsThread
{
//vairables that are not a concern here
UpdateFromGui(A_ComposingClass_B_Object*,const bool&,const bool&);
};
Here is the deal when I run the code as is, there is a steady increase in memory size but when I comment out the Call to UpdateFromGui call in UpdateGuiWithData class, the memory stays at a constant level of around 51 MB. The UpdateFromGui function has no dynamic memory allocation or GUI functions. It is just a plane jane function that constructs the packet to write to serial port and is called 10 times a second since this is the refresh rate of the hardware.
The only reason I could think of the increase in memory is passing the array of objects with each call to UpdateFromGui function. I think with each call we are creating a copy of class objects and hence the increase in memory. Then I tried to use passing array of objects as reference to the function but couldn't find a suitable declaration for such a function, though I found the definition and usage of such a function. Here is what I found on the net.
// Receive Array by reference.
void GetArray( int (&Array) [10] )
{
}
// Test array by reference.
void CRabbitDlgDlg::TestArray()
{
// Pass array by reference.
int Array[10] = { 0 };
GetArray( Array );
}
My question are
--->Am I thinking on the right line or is it something to do with repeated call to singleton
class object?
--->Also do I need a copy constructor here for Class A, though there is no dynamic
allocation or pointer variables in this class?
--->What else can be the source of this memory leak (if not its not about copy constructor or singleton calls) which constantly increases the memory usage
of the application?