PDA

View Full Version : QList: out of memory



navi1084
22nd March 2009, 11:34
Hi,
I have a class called CMyClass. My application has list of CMyClass object. Module2 is used to create and delete the CMyClass object and append to the Qlist which is in Module1.
The declaration of the QList as follows:
QList<CMyClass *>* listObject = new QList<CMyClass *>();
Initially if i am appending the CMyClass object listObject works fine. if I remove last item from the listObject and try to append one more CMyClass object, then following error occures:
QList: out of memory

This error only occures only if I delete one item from list and try to append one more.

When i debug the program it was crashing in following code(red color):

Q_OUTOFLINE_TEMPLATE void QList<T>::detach_helper()
{
Node *n = reinterpret_cast<Node *>(p.begin());
QListData::Data *x = p.detach2();
node_copy(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.end()), n);
if (!x->ref.deref())
free(x);
}


Following are the Call stack:
QtCored4.dll!qt_message_output(QtMsgType msgType=QtFatalMsg, const char * buf=0x001298d4) Line 2032 C++
QtCored4.dll!qFatal(const char * msg=0x6723a96c, ...) Line 2238 + 0xe bytes C++
QtCored4.dll!QListData::detach2() Line 76 + 0xa bytes C++
MainAppd.dll!QList<MyListholdingClass *>::detach_helper() Line 500 + 0x9 bytes C++
MainAppd.dll!QList<MyListholdingClass *>::detach() Line 99 + 0x23 bytes C++
MainAppd.dll!QList<MyListholdingClass *>::append(MyListholdingClass * const & t=0x0432fd50) Line 401 C++

Can anyone please tell me how can i resolve this.

spirit
22nd March 2009, 11:40
can you show all code?
btw, what the reason of creation a list in the heap?

navi1084
22nd March 2009, 11:53
Thank you for the reply
I am using following code


QList<CMyClass *>* listObject = new QList<CMyClass *>();

To Add I am using following function:

void addobject(CMyClass *myObject)
{
listObject->append(myObject);
}


void removeObject()
{
listObject->removeAt(i);
}

In the destructor of CMyClass i am emitting a signal to delete the object from the list which remove the objct successfully (variable 'i' is calculated inside removeObject). 'delete' operation of the CMyClass object will be done wherever i create it.

spirit
22nd March 2009, 12:00
you did not answer on my question :)
try to modify your code like this


QList<CMyClass *> listObject;//make this variable as class-member.

void addobject(CMyClass *myObject)
{
listObject.append(myObject);
}


void removeObject()
{
listObject.removeAt(i); //btw, in this case pointer will not be free.
//use QList::takeAt instead.
//delete listObject.takeAt(i);
}

navi1084
22nd March 2009, 12:03
Sorry I cant show my all the codes. But i can say CMyClass is a abstract class which contains large amount of data.

navi1084
22nd March 2009, 12:30
Can anyone please help me out

aamer4yu
23rd March 2009, 10:27
Why dont you try modifying your code as spirit suggested.
Is there any special reason u are creating list on heap ? QList manages memory well, so why are u taking the headache ?