Hi,
I am facing the following problem related to memory allocation and deallocation:
Xtreme ToolkitPro v15.3.1
I have allocated a number of CXTPChartSeriesPoint instances on the chart using CXTPChartFastLineSeriesStyle. After processing, I have called the RemoveAll() function for the class CXTPChartSeriesCollection. I am expecting that the memory allocated earlier will be deallocated and the free space in the user space (the amount of memory available to the process) will recover after calling RemoveAll() function, but it does not. Eventually, the process runs out of memory.
Could anyone please help me with this issue?
Here my code: void CFastLineView::AddPoint() { CXTPChartContent* pContent = m_wndChartControl.GetContent(); CXTPChartSeriesCollection* pCollection = pContent->GetSeries();
int nCount; if (pCollection) { for (int s = 0; s < pCollection->GetCount(); s++) { CXTPChartSeries* pSeries = pCollection->GetAt(s); if (pSeries) { int nValue = 50;
nCount = pSeries->GetPoints()->GetCount(); if (nCount) nValue = (int)pSeries->GetPoints()->GetAt(nCount - 1)->GetValue(0); nValue = nValue + (rand() % 20) - 10; if (nValue < 0) nValue = 0; if (nValue > 100) nValue = 100; pSeries->GetPoints()->Add(new CXTPChartSeriesPoint(nCount, nValue));
} } }
CXTPChartDiagram2D* pDiagram = DYNAMIC_DOWNCAST(CXTPChartDiagram2D, m_wndChartControl.GetContent()->GetPanels()->GetAt(0)); ASSERT (pDiagram);
if (nCount > 100) { CXTPChartAxisRange* pRange = pDiagram->GetAxisX()->GetRange();
BOOL bAutoScroll = pRange->GetViewMaxValue() == pRange->GetMaxValue();
pRange->SetMaxValue(nCount);
if (bAutoScroll) { double delta = pRange->GetViewMaxValue() - pRange->GetViewMinValue();
pRange->SetViewAutoRange(FALSE); pRange->SetViewMaxValue(nCount); pRange->SetViewMinValue(nCount - delta); } } }
// 1msec Interval void CFastLineView::OnTimer(UINT_PTR nIDEvent) { for (int i = 0; i < 1000; i++){ AddPoint(); } }
// Collection, point initialization void CFastLineView::CollectionRemoveAll() { CXTPChartContent* pContent = m_wndChartControl.GetContent(); CXTPChartSeriesCollection* pCollection = pContent->GetSeries(); pCollection->RemoveAll(); }
// Event when button is pressed void CFastLineView::OnButton() { CString str; MEMORYSTATUSEX memstat; memstat.dwLength = sizeof(memstat); if (GlobalMemoryStatusEx(&memstat)) { str.Format("%dMB", memstat.ullAvailVirtual/(1024*1024)); AfxMessageBox(str); // Example output: 1000MB } CollectionRemoveAll(); if (GlobalMemoryStatusEx(&memstat)) { str.Format("%dMB", memstat.ullAvailVirtual/(1024*1024)); AfxMessageBox(str); // Example output: 1000MB (memory not recovered) } }
|