473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to serialize in "destructor" ?

I have a class which has a member variable of the type System.ArrayList.
I plan on having the ArrayList serialize/deserialize itself to/from XML. I
have worked out the code to do this and have the ArrayList is currently
deserializing in the constructor. When is the correct time to serialize the
ArrayList to XML? In C++ I would do this in the destructor. I see C# has a
destructor, but I am unsure about all of this IDisposable, Finalize, Dispose
and such. When would I perform cleanup code? Could someone explain these
terms to me ? Are there any source examples on MSDN to explain this ?
Nov 15 '05 #1
2 2595
"Trevor Balcom" <tb*****@attbi.co> wrote in message news:<#e*************@TK2MSFTNGP10.phx.gbl>...
I have a class which has a member variable of the type System.ArrayList.
I plan on having the ArrayList serialize/deserialize itself to/from XML. I
have worked out the code to do this and have the ArrayList is currently
deserializing in the constructor. When is the correct time to serialize the
ArrayList to XML? In C++ I would do this in the destructor. I see C# has a
destructor, but I am unsure about all of this IDisposable, Finalize, Dispose
and such. When would I perform cleanup code? Could someone explain these
terms to me ? Are there any source examples on MSDN to explain this ?


You shouldn't even consider seralizing in the finalizer. As far as I know, when
the finalizer is executed, you can't guarantee that all objects that would have
been part of your object graph would still be available in memory. You might
consider seralizing explicitly before program termination. Or periodically if
that is not possible.

You might want to further explain the current porblem that you are trying to
solve here.

-LM
Nov 15 '05 #2
Lucean Morningside <m@exquisitor.com> wrote:
You shouldn't even consider seralizing in the finalizer. As far as I know, when
the finalizer is executed, you can't guarantee that all objects that would have
been part of your object graph would still be available in memory.


I believe you can - they're still strongly reachable while your object
is strongly reachable. However, they may have been finalized before you
have, and generally not be in a very useful state. I agree it's not a
good idea to do anything like serialization in the finalizer though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jahn Otto Næsgaard Andersen | last post by:
Hi, I have a class A with a static pointer to some data. The pointer is static because I want to access the data from all instances of the class. The data itself is allocated when the first...
3
by: Alfred E Neuman | last post by:
I've read that... AClass ac = AClass( "name", 23 ); is less efficient than... AClass ac( "name", 23 ); because the first has to create a temporary object which is then assigned to ac. ...
87
by: ziliath | last post by:
I recently tried out the Google "top coder" contest, as a C++ coder. I noticed immediately that they expected me to know STL. To which I say, what the fuck?! I may be missing something, but at...
32
by: Christopher Benson-Manica | last post by:
Is the following code legal, moral, and advisable? #include <iostream> class A { private: int a; public: A() : a(42) {}
6
by: R.Z. | last post by:
i'm using a class from some api that is said to automatically call its destructor when its out of scope and deallocate memory. i create instances of this class using "new" operator. do i have to...
10
by: Paul | last post by:
Hi, I was wondering if anyone knows if it is possible in C# given x,y coordinates of several straight lines to draw these on the screen and then save this as an image file, also adding text to the...
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
8
by: gw7rib | last post by:
I've been bitten twice now by the same bug, and so I thought I would draw it to people's attention to try to save others the problems I've had. The bug arises when you copy code from a destructor...
7
by: eric | last post by:
hello i'm confused by an example in the book "Effective C++ Third Edition" and would be grateful for some help. here's the code: class Person { public: Person(); virtual ~Person(); // see...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.