deallocate the heap memory. - Programmer

This is a discussion on deallocate the heap memory. - Programmer ; Hi, I got a wierd problem, I got a function XYZ() where I am creating some memory inside a for loop (using new operator) and performing some logic and pushing it into a vector. And later I am using the ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: deallocate the heap memory.

  1. deallocate the heap memory.

    Hi,
    I got a wierd problem, I got a function XYZ() where I am creating some
    memory inside a for loop (using new operator) and performing some
    logic and pushing it into a vector. And later I am using the vector
    throug out my dll functions.

    And I am deleting the memory allocated before I call XYZ() function.



    Code snap shot
    Class A
    void ABC()
    {
    m_pclassB = new CMyClassB();
    for(itr = m_vecdesignlist.begin();itr < m_vecdesignlist.end();itr++)
    {
    ptempdesignlist = (*itr);
    if(ptempdesignlist != NULL)
    delete ptempdesignlist ;
    }
    m_pclassB->XYZ( strtemp, m_vecdesignlist);

    }

    Class B

    void XYZ (str, m_veclist)
    {
    for (long i= 0; i {
    m_vecdesignlist.clear();
    m_pJobs = new JOBS;
    doing something with m_pJobs
    ........................
    ........................

    m_vecdesignlist.push_back(m_pJobs);
    }

    each time I excute my ABC() function new memory is created and the
    memory usage in the task manager gets incremented but the memory that i
    am deleting in ABC() before i call XYZ() is not decrementing. Task
    manager memory usage column always shows up the same that got
    incremented.


    I appreciate all your suggestion to overcome this issue.


    Thanks
    Lucky


  2. Re: deallocate the heap memory.

    I don't see where you're deleting m_pclassB = new CMyClassB();
    Also, depending on how you're using this, you may need to call
    m_vecdesignlist.clear() to remove all the elements from the vector
    after ABC() finishes.

    Lucky wrote:
    > Hi,
    > I got a wierd problem, I got a function XYZ() where I am creating some
    > memory inside a for loop (using new operator) and performing some
    > logic and pushing it into a vector. And later I am using the vector
    > throug out my dll functions.
    >
    > And I am deleting the memory allocated before I call XYZ() function.
    >
    >
    >
    > Code snap shot
    > Class A
    > void ABC()
    > {
    > m_pclassB = new CMyClassB();
    > for(itr = m_vecdesignlist.begin();itr < m_vecdesignlist.end();itr++)
    > {
    > ptempdesignlist = (*itr);
    > if(ptempdesignlist != NULL)
    > delete ptempdesignlist ;
    > }
    > m_pclassB->XYZ( strtemp, m_vecdesignlist);
    >
    > }
    >
    > Class B
    >
    > void XYZ (str, m_veclist)
    > {
    > for (long i= 0; i > {
    > m_vecdesignlist.clear();
    > m_pJobs = new JOBS;
    > doing something with m_pJobs
    > ........................
    > ........................
    >
    > m_vecdesignlist.push_back(m_pJobs);
    > }
    >
    > each time I excute my ABC() function new memory is created and the
    > memory usage in the task manager gets incremented but the memory that i
    > am deleting in ABC() before i call XYZ() is not decrementing. Task
    > manager memory usage column always shows up the same that got
    > incremented.
    >
    >
    > I appreciate all your suggestion to overcome this issue.
    >
    >
    > Thanks
    > Lucky



+ Reply to Thread