473,513 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ICloneable and releasing memory

ib
ICloneable::Clone returns a new instance of the object being cloned.
However, it seems possible that the garbage collector could release this
memory before the calling function receives a reference to the memory. If
this can occur then it introduces an error that would only occur at random
times. Is this really a problem or does .NET take the necessary steps to
ensure the memory is first referenced by the calling function before the
garbage collector gets a chance to check the memory?

Thanks,

Ian
Dec 5 '06 #1
3 1555
Hi Ian,

I don't see why returning a new object from a method named, "Clone" would be
any different, in terms of GC, from returning a new object from any other
method. What exactly is your concern here?

--
Dave Sexton

"ib" <ib@yahoo.comwrote in message
news:NY**********************@wagner.videotron.net ...
ICloneable::Clone returns a new instance of the object being cloned.
However, it seems possible that the garbage collector could release this
memory before the calling function receives a reference to the memory.
If this can occur then it introduces an error that would only occur at
random times. Is this really a problem or does .NET take the necessary
steps to ensure the memory is first referenced by the calling function
before the garbage collector gets a chance to check the memory?

Thanks,

Ian

Dec 5 '06 #2

ib wrote:
ICloneable::Clone returns a new instance of the object being cloned.
However, it seems possible that the garbage collector could release this
memory before the calling function receives a reference to the memory. If
this can occur then it introduces an error that would only occur at random
times. Is this really a problem or does .NET take the necessary steps to
ensure the memory is first referenced by the calling function before the
garbage collector gets a chance to check the memory?
Why would the memory have to be referenced "by the calling function"?

There is a reference to the memory on the stack, either as a local
variable in the Clone method, as a return value from the Clone method,
or as a local variable in the calling method. Since the GC walks the
stack as one of its ways of determining what is currently in use, it
will find a reference to the memory throughout the cloning process.

It's no different from new-ing an object and returning it from any
other method.

Dec 5 '06 #3
ib
Please disregard this posting. I have posted it else where.

Thanks,

Ian
Dec 5 '06 #4

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

Similar topics

4
3030
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
4
1928
by: smith | last post by:
I've been making deep copy clones of objects since my second week or so with ..Net (it took me the first week to realize that shallow copies were usually worthless as "clones"). Normally I call my...
7
25954
by: trialproduct2004 | last post by:
Hi all I am having application in c# where i am loading one table of database into dataset. My table is of large size. so whenever i am loading that into dataset my memory size is getting...
2
2202
by: M.Ob | last post by:
Hello... I am having issues with my asp.net apps not releasing memory. The memory usage for the process w3p.exe continues to grow to it's allowable limit and does not drop until the app pool is...
7
26420
by: Don | last post by:
Can anyone give me an example of implementing ICloneable to give a class I created a "Clone" method so I can make copies of objects. I have no idea where to begin with this. Thanks. - Don
8
11958
by: Sean | last post by:
I have a service that is pulling alot of records from a SQL Server table in a DataSet. This process takes up alot of memory, which is to be expected. But when the process is finished, I am clearing...
1
2279
by: Rain | last post by:
Hi. Im a C# newbie, just want to ask how to implement the ICloneable.Clone.. Dont know how it works, would really appreciate it if someone could show a simple source sample of how to do this.....
2
19445
by: Nathan | last post by:
I'm working with Clone() for the first time, and noticed that you have to unbox the Clone of an object that implements ICloneable: MyObject var1 = new MyObject(); // Where MyObject implements...
12
3129
by: iker.arizmendi | last post by:
Is there any way to get Python to release memory back to the C allocator? I'm currently running a script that goes through the following steps: 1) Creates a very large number of Python objects...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7535
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...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5683
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,...
1
5085
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...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.