Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 4 of 4 total |
Memory leak |
Thu, Nov 11 2010 2:49 PM | Permanent Link |
Jose Eduardo Helminsky HPro Informatica | Tim
One thing I would like to know is why the code below produces memory leak if the scope of Table is local. procedure test; var Table: TDBISamTable; begin Table := TDBISamTable.Create(nil); Table.TableName := 'x'; Table.Open; // routine end; Look that there is neither a close nor free methods, but like I wrote above why this is wrong ? Actually I am using other aproach. procedure test; var Table: TDBISamTable; begin Table := TDBISamTable.Create(nil); try Table.TableName := 'x'; Table.Open; // routine finally Table.Close; Table.Free; end; end; Eduardo |
Thu, Nov 11 2010 3:12 PM | Permanent Link |
Shane McCall | Eduardo,
You have specified no owner for the table, so you are responsible for freeing the component when you are done with it. Components free their owned components when they are released, but if a component has no owner there is nothing that will release it automatically. If you really want to keep this table open for the entire time the application is active, use Table := TDBISAMTable.Create(Application); and it will be freed when the application is destroyed. Sean Eduardo [HPro] wrote: > Tim > > One thing I would like to know is why the code below produces memory leak if > the scope of Table is local. > > procedure test; > var Table: TDBISamTable; > begin > Table := TDBISamTable.Create(nil); > Table.TableName := 'x'; > Table.Open; > // routine > end; > > Look that there is neither a close nor free methods, but like I wrote above > why this is wrong ? > > Actually I am using other aproach. > > procedure test; > var Table: TDBISamTable; > begin > Table := TDBISamTable.Create(nil); > try > Table.TableName := 'x'; > Table.Open; > // routine > finally > Table.Close; > Table.Free; > end; > end; > > Eduardo > > |
Fri, Nov 12 2010 5:19 AM | Permanent Link |
John Hay | Eduardo
> One thing I would like to know is why the code below produces memory leak if > the scope of Table is local. > > procedure test; > var Table: TDBISamTable; > begin > Table := TDBISamTable.Create(nil); > Table.TableName := 'x'; > Table.Open; > // routine > end; > > Look that there is neither a close nor free methods, but like I wrote above > why this is wrong ? The pointer Table is a local variable and its memory is reclaimed when the procedure finishes. The class TDBISamTable is created on the heap and its memory is reclaimed when it is explicitly freed or its owner is freed. With a nil owner it is never freed. Remember that Table is only a pointer to the class, not the class itself. John |
Fri, Nov 12 2010 11:50 AM | Permanent Link |
Jose Eduardo Helminsky HPro Informatica | John and Sean
Thank you for both. Eduardo |
This web page was last updated on Thursday, March 28, 2024 at 08:36 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |