r20010 - gnucash/trunk/src/engine - When book is being closed, destroy objects to free their memory. Doesn't matter too much when closing gnucash,

Phil Longstaff plongstaff at code.gnucash.org
Thu Dec 30 20:42:39 EST 2010


Author: plongstaff
Date: 2010-12-30 20:42:39 -0500 (Thu, 30 Dec 2010)
New Revision: 20010
Trac: http://svn.gnucash.org/trac/changeset/20010

Modified:
   gnucash/trunk/src/engine/gncCustomer.c
   gnucash/trunk/src/engine/gncEmployee.c
   gnucash/trunk/src/engine/gncEntry.c
   gnucash/trunk/src/engine/gncJob.c
   gnucash/trunk/src/engine/gncVendor.c
Log:
When book is being closed, destroy objects to free their memory.  Doesn't matter too much when closing gnucash,
but when closing one book to open another, all memory from the old book should be freed.


Modified: gnucash/trunk/src/engine/gncCustomer.c
===================================================================
--- gnucash/trunk/src/engine/gncCustomer.c	2010-12-31 01:38:37 UTC (rev 20009)
+++ gnucash/trunk/src/engine/gncCustomer.c	2010-12-31 01:42:39 UTC (rev 20010)
@@ -865,6 +865,28 @@
     return gncCustomerGetName((GncCustomer*)item);
 }
 
+static void
+destroy_customer_on_book_close(QofInstance *ent, gpointer data)
+{
+    GncCustomer* c = GNC_CUSTOMER(ent);
+
+    gncCustomerBeginEdit(c);
+    gncCustomerDestroy(c);
+}
+
+/** Handles book end - frees all customers from the book
+ *
+ * @param book Book being closed
+ */
+static void
+gnc_customer_book_end(QofBook* book)
+{
+    QofCollection *col;
+
+    col = qof_book_get_collection(book, GNC_ID_CUSTOMER);
+    qof_collection_foreach(col, destroy_customer_on_book_close, NULL);
+}
+
 static QofObject gncCustomerDesc =
 {
     DI(.interface_version = ) QOF_OBJECT_VERSION,
@@ -872,7 +894,7 @@
     DI(.type_label        = ) "Customer",
     DI(.create            = ) (gpointer)gncCustomerCreate,
     DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
+    DI(.book_end          = ) gnc_customer_book_end,
     DI(.is_dirty          = ) qof_collection_is_dirty,
     DI(.mark_clean        = ) qof_collection_mark_clean,
     DI(.foreach           = ) qof_collection_foreach,

Modified: gnucash/trunk/src/engine/gncEmployee.c
===================================================================
--- gnucash/trunk/src/engine/gncEmployee.c	2010-12-31 01:38:37 UTC (rev 20009)
+++ gnucash/trunk/src/engine/gncEmployee.c	2010-12-31 01:42:39 UTC (rev 20010)
@@ -671,6 +671,28 @@
     gncEmployeeCommitEdit(empl);
 }
 
+static void
+destroy_employee_on_book_close(QofInstance *ent, gpointer data)
+{
+    GncEmployee* e = GNC_EMPLOYEE(ent);
+
+    gncEmployeeBeginEdit(e);
+    gncEmployeeDestroy(e);
+}
+
+/** Handles book end - frees all employees from the book
+ *
+ * @param book Book being closed
+ */
+static void
+gnc_employee_book_end(QofBook* book)
+{
+    QofCollection *col;
+
+    col = qof_book_get_collection(book, GNC_ID_EMPLOYEE);
+    qof_collection_foreach(col, destroy_employee_on_book_close, NULL);
+}
+
 static QofObject gncEmployeeDesc =
 {
     DI(.interface_version = ) QOF_OBJECT_VERSION,
@@ -678,7 +700,7 @@
     DI(.type_label        = ) "Employee",
     DI(.create            = ) (gpointer)gncEmployeeCreate,
     DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
+    DI(.book_end          = ) gnc_employee_book_end,
     DI(.is_dirty          = ) qof_collection_is_dirty,
     DI(.mark_clean        = ) qof_collection_mark_clean,
     DI(.foreach           = ) qof_collection_foreach,

Modified: gnucash/trunk/src/engine/gncEntry.c
===================================================================
--- gnucash/trunk/src/engine/gncEntry.c	2010-12-31 01:38:37 UTC (rev 20009)
+++ gnucash/trunk/src/engine/gncEntry.c	2010-12-31 01:42:39 UTC (rev 20010)
@@ -1533,6 +1533,28 @@
 /* ============================================================= */
 /* Object declaration */
 
+static void
+destroy_entry_on_book_close(QofInstance *ent, gpointer data)
+{
+    GncEntry* entry = GNC_ENTRY(ent);
+
+    gncEntryBeginEdit(entry);
+    gncEntryDestroy(entry);
+}
+
+/** Handles book end - frees all entries from the book
+ *
+ * @param book Book being closed
+ */
+static void
+gnc_entry_book_end(QofBook* book)
+{
+    QofCollection *col;
+
+    col = qof_book_get_collection(book, GNC_ID_ENTRY);
+    qof_collection_foreach(col, destroy_entry_on_book_close, NULL);
+}
+
 static QofObject gncEntryDesc =
 {
     DI(.interface_version = ) QOF_OBJECT_VERSION,
@@ -1540,7 +1562,7 @@
     DI(.type_label        = ) "Order/Invoice/Bill Entry",
     DI(.create            = ) (gpointer)gncEntryCreate,
     DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
+    DI(.book_end          = ) gnc_entry_book_end,
     DI(.is_dirty          = ) qof_collection_is_dirty,
     DI(.mark_clean        = ) qof_collection_mark_clean,
     DI(.foreach           = ) qof_collection_foreach,

Modified: gnucash/trunk/src/engine/gncJob.c
===================================================================
--- gnucash/trunk/src/engine/gncJob.c	2010-12-31 01:38:37 UTC (rev 20009)
+++ gnucash/trunk/src/engine/gncJob.c	2010-12-31 01:42:39 UTC (rev 20010)
@@ -511,6 +511,27 @@
     return c->name;
 }
 
+static void
+destroy_job_on_book_close(QofInstance *ent, gpointer data)
+{
+    GncJob* job = GNC_JOB(ent);
+
+    gncJobFree(job);
+}
+
+/** Handles book end - frees all jobs from the book
+ *
+ * @param book Book being closed
+ */
+static void
+gnc_job_book_end(QofBook* book)
+{
+    QofCollection *col;
+
+    col = qof_book_get_collection(book, GNC_ID_JOB);
+    qof_collection_foreach(col, destroy_job_on_book_close, NULL);
+}
+
 static QofObject gncJobDesc =
 {
     DI(.interface_version = ) QOF_OBJECT_VERSION,

Modified: gnucash/trunk/src/engine/gncVendor.c
===================================================================
--- gnucash/trunk/src/engine/gncVendor.c	2010-12-31 01:38:37 UTC (rev 20009)
+++ gnucash/trunk/src/engine/gncVendor.c	2010-12-31 01:42:39 UTC (rev 20010)
@@ -781,6 +781,28 @@
     return v->name;
 }
 
+static void
+destroy_vendor_on_book_close(QofInstance *ent, gpointer data)
+{
+    GncVendor* v = GNC_VENDOR(ent);
+
+    gncVendorBeginEdit(v);
+    gncVendorDestroy(v);
+}
+
+/** Handles book end - frees all vendors from the book
+ *
+ * @param book Book being closed
+ */
+static void
+gnc_vendor_book_end(QofBook* book)
+{
+    QofCollection *col;
+
+    col = qof_book_get_collection(book, GNC_ID_VENDOR);
+    qof_collection_foreach(col, destroy_vendor_on_book_close, NULL);
+}
+
 static QofObject gncVendorDesc =
 {
     DI(.interface_version = ) QOF_OBJECT_VERSION,
@@ -788,7 +810,7 @@
     DI(.type_label        = ) "Vendor",
     DI(.create            = ) (gpointer)gncVendorCreate,
     DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
+    DI(.book_end          = ) gnc_vendor_book_end,
     DI(.is_dirty          = ) qof_collection_is_dirty,
     DI(.mark_clean        = ) qof_collection_mark_clean,
     DI(.foreach           = ) qof_collection_foreach,



More information about the gnucash-changes mailing list