When a book is closed, all of the memory for the objects should be freed.

Free budgets and invoices.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19987 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2010-12-29 01:43:28 +00:00
parent c42190fb11
commit af2e6b3fa4
2 changed files with 41 additions and 2 deletions

View File

@ -635,6 +635,27 @@ gnc_budget_get_default (QofBook *book)
return bgt;
}
static void
destroy_budget_on_book_close(QofInstance *ent, gpointer data)
{
GncBudget* bgt = GNC_BUDGET(ent);
gnc_budget_destroy(bgt);
}
/** Handles book end - frees all budgets from the book
*
* @param book Book being closed
*/
static void
gnc_budget_book_end(QofBook* book)
{
QofCollection *col;
col = qof_book_get_collection(book, GNC_ID_BUDGET);
qof_collection_foreach(col, destroy_budget_on_book_close, NULL);
}
#ifdef _MSC_VER
/* MSVC compiler doesn't have C99 "designated initializers"
* so we wrap them in a macro that is empty on MSVC. */
@ -651,7 +672,7 @@ static QofObject budget_object_def =
DI(.type_label = ) "Budget",
DI(.create = ) (gpointer)gnc_budget_new,
DI(.book_begin = ) NULL,
DI(.book_end = ) NULL,
DI(.book_end = ) gnc_budget_book_end,
DI(.is_dirty = ) qof_collection_is_dirty,
DI(.mark_clean = ) qof_collection_mark_clean,
DI(.foreach = ) qof_collection_foreach,

View File

@ -2014,6 +2014,24 @@ static const char * _gncInvoicePrintable (gpointer obj)
return invoice->printname;
}
static void
destroy_invoice_on_book_close(QofInstance *ent, gpointer data)
{
GncInvoice* invoice = GNC_INVOICE(ent);
gncInvoiceBeginEdit(invoice);
gncInvoiceDestroy(invoice);
}
static void
gnc_invoice_book_end(QofBook* book)
{
QofCollection *col;
col = qof_book_get_collection(book, GNC_ID_INVOICE);
qof_collection_foreach(col, destroy_invoice_on_book_close, NULL);
}
static QofObject gncInvoiceDesc =
{
DI(.interface_version = ) QOF_OBJECT_VERSION,
@ -2021,7 +2039,7 @@ static QofObject gncInvoiceDesc =
DI(.type_label = ) "Invoice",
DI(.create = ) (gpointer)gncInvoiceCreate,
DI(.book_begin = ) NULL,
DI(.book_end = ) NULL,
DI(.book_end = ) gnc_invoice_book_end,
DI(.is_dirty = ) qof_collection_is_dirty,
DI(.mark_clean = ) qof_collection_mark_clean,
DI(.foreach = ) qof_collection_foreach,