|
넵.. 빠른 답변은 감사합니다.
위의 코드는 줄여서 적었습니다.
그리고 생성자와 소멸자에서 new와 delete는 해 주고 있습니다.
지금 답글에 보면 TStringList에 관한 얘기는 없는듯 합니다.
음 TStringList 객체 m_pStrList에 100개의 String을 가지고 있어야 하기에 필요합니다.
용수님 처럼 하는게 아니라 TStringList 객체 m_pStrList의 String를 ListView에 뿌려주고 있습니다.
근데 m_pStrList에 Insert 부분에서 100개만 잡고 있기 때문에 메모리가 일정부분증가하고 증가를
안해야 된다고 생각이 드는데요 ^^ 그리고 메모리가 증가하더라도 Clear부분에서 메모리해제를 해주는데
메모리해제가 안되는 이유를 여쭤 본겁니다.
아래 소스는 제가 따로 테스트를 해 봤지만 메모리는 줄지 않는것 같습니다.
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
m_pStrList = new TStringList();
m_nCount = 0;
}
TForm1::~TForm1()
{
if( m_pStrList )
{
m_pStrList->Clear();
delete m_pStrList;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
String strMsg;
strMsg.sprintf("Test:%d",m_nCount++);
if( m_pStrList->Count == 100 )
{
m_pStrList->Delete( 99 );
m_pStrList->Insert( 0, strMsg );
Memo1->Lines->Insert( 0, strMsg );
}
else
{
Memo1->Lines->Insert( 0, strMsg );
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if( m_pStrList )
{
int nCnt =m_pStrList->Count;
for( int n = nCnt - 1 ; n >= 0 ; n-- )
{
m_pStrList->Strings[n] = "";
m_pStrList->Delete(n);
}
m_pStrList->Clear();
}
if( Timer1->Enabled )
{
Timer1->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if( !Timer1->Enabled )
{
Timer1->Enabled = true;
m_nCount = 0;
}
}
|