Article View: borland.public.cppbuilder.nativeapi
Article #2611Re: Memory Leak - TForm or TStringGrid or DynamicArray
From: Clayton Arends
Date: Mon, 05 Feb 2007 20:55
Date: Mon, 05 Feb 2007 20:55
29 lines
2027 bytes
2027 bytes
The data in the "Objects" property is not owned by the string grid. The
string grid makes no assumptions as to its contents. It is there solely for
the developer's needs.
To delete your objects you need to do something like the following.
// In the form's destructor
for (int col = 0, colCount = StringGrid1->ColCount;
col < colCount; ++col)
{
for (int row = 0, rowCount = StringGrid1->RowCount;
row < rowCount; ++row)
{
delete StringGrid1->Objects[col][row];
StringGrid1->Objects[col][row] = NULL; // optional
}
}
The above code assumes that the data stored in the objects array are truly
pointers to TObject descendants. If they are not then you will need to
reinterpret_cast to the appropriate type for delete to work correctly.
> The button click event fills in a number of static objects with random
> data
What do you mean by static objects? Can you show some code to explain what
you mean?
- Clayton
Technical Details
Message-ID:
<45c7994e$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!homer!news.glorb.com!news-spur1.glorb.com!news.glorb.com!newspeer2.de.telia.net!newspeer3.de.telia.net!de.telia.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45c7810f@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,191a7d21d69bde32 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Clayton Arends" <nospam_claytonarends@hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <45c7810f@newsgroups.borland.com> Subject: Re: Memory Leak - TForm or TStringGrid or DynamicArray Date: Mon, 5 Feb 2007 12:55:06 -0800 Lines: 31 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 71.93.4.222 Message-ID: <45c7994e$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1170708814 71.93.4.222 (5 Feb 2007 12:53:34 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!homer!news.glorb.com!news-spur1.glorb.com!news.glorb.com!newspeer2.de.telia.net!newspeer3.de.telia.net!de.telia.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail