How to destroy temp object correctly c# -



How to destroy temp object correctly c# -

i need help creation , destruction of objects or life cycle of objects. problem after disposing form temp objects not erased , relations object still exists. doing wrong? need override dispose method or destructor somehow? how destroy temp object correctly? thanks.

product form:

private product t = null; public productform(customer cust) { initializecomponent(); t = new product(); t.customer = cust; } public copyproducts(list<product> copy_from) { foreach(product temp1 in copy_from) { product temp2 = new product(); temp2.customer = t.customer; temp2.count = temp1.count; temp2.delivery = temp1. delivery; … cdb.product.insertonsubmit(temp2); cdb.submitchanges(); } } private void okbutton_click(object sender, eventargs e) { t.count = … … cdb.product.insertonsubmit(t); cdb.submitchanges(); } private void cancelbutton_click(object sender, eventargs e) { this.close(); }

test code in main form:

messagebox.show(current_customer.product.count().tostring()); // ->>> 10 productform prodform = new productform(current_customer); prodform.showdialog(); prodform.dispose(); // ->>> after cancel button clicked should 10 shouws 11 messagebox.show(current_customer.product.count().tostring()); // ->>> 11 instead of 10

and

messagebox.show(current_customer.product.count().tostring()); // ->>> 10 productform prodform = new productform(current_customer); prodform.copyproducts(list_of_products); prodform.dispose(); messagebox.show(current_customer.product.count().tostring()); // ->>> 11 instead of 10

when disposing form not impact current_customer because has nil it. when dispose form 1 reference instance current_customer released, long references exist (within main app e.g.) actual instance exists further. therefor still ha value.

edit: maybe can show more code increment count.

c#

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -