473,386 Members | 1,810 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,386 software developers and data experts.

Swapping the object instance in dot net

Hi All

Here i am facing one technical issue related to Swapping the Object Instance
in Dotnet.

e.g..

class Customer{

Order _lastOrder;

void insertOrder (int ID, int quantity, double amount, int productId)

Order currentOrder = new Order(ID, quantity, amount, productID);

currentOrder.Insert();

this._lastOrder = currentOrder

}
this is my class, when i try to swap the currentOrder instance to
_lastOrder, what could happen for the currentOrder object memory, whether it
will destroy immediately or what is the stage. As per the Microsoft
suggestion avoid this type of code because it increases the likelihood of the
object being promoted beyond Gen 0, which delays the object's resources from
being reclaimed.

I am using this type of Swapping in my application very frequently, if it
so, whether memory will grow,

can any one please suggest your valuable inputs in this, by how to handle
this type of scenario.
Jul 21 '05 #1
16 1580
<"=?Utf-8?B?U2V0aHUgTWFkaGF2YW4=?=" <Sethu
Ma******@discussions.microsoft.com>> wrote:
Here i am facing one technical issue related to Swapping the Object Instance
in Dotnet.

e.g..

class Customer{

Order _lastOrder;

void insertOrder (int ID, int quantity, double amount, int productId)

Order currentOrder = new Order(ID, quantity, amount, productID);

currentOrder.Insert();

this._lastOrder = currentOrder

}
this is my class, when i try to swap the currentOrder instance to
_lastOrder, what could happen for the currentOrder object memory, whether it
will destroy immediately or what is the stage.
Assuming there are no other live references to it, it will be collected
next time the generation it lives in is garbage collected.
As per the Microsoft suggestion avoid this type of code because it
increases the likelihood of the object being promoted beyond Gen 0,
which delays the object's resources from being reclaimed.
I don't recall seeing any recommendations particularly against this
type of code. Could you give a link to the page you're talking about?
I am using this type of Swapping in my application very frequently, if it
so, whether memory will grow,

can any one please suggest your valuable inputs in this, by how to handle
this type of scenario.


Well, I wouldn't worry about it, personally. The garbage collector is
pretty good, and while it's worth keeping an eye on the memory to be
sure, you'll probably find it isn't a problem.

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


"Jon Skeet [C# MVP]" wrote:
<"=?Utf-8?B?U2V0aHUgTWFkaGF2YW4=?=" <Sethu
Ma******@discussions.microsoft.com>> wrote:
Here i am facing one technical issue related to Swapping the Object Instance
in Dotnet.

e.g..

class Customer{

Order _lastOrder;

void insertOrder (int ID, int quantity, double amount, int productId)

Order currentOrder = new Order(ID, quantity, amount, productID);

currentOrder.Insert();

this._lastOrder = currentOrder

}
this is my class, when i try to swap the currentOrder instance to
_lastOrder, what could happen for the currentOrder object memory, whether it
will destroy immediately or what is the stage.
Assuming there are no other live references to it, it will be collected
next time the generation it lives in is garbage collected.
As per the Microsoft suggestion avoid this type of code because it
increases the likelihood of the object being promoted beyond Gen 0,
which delays the object's resources from being reclaimed.


I don't recall seeing any recommendations particularly against this
type of code. Could you give a link to the page you're talking about?


the link page is
http://msdn.microsoft.com/library/de...netchapt05.asp

under the paragraph "Prevent the Promotion of Short-Lived Objects"
I am using this type of Swapping in my application very frequently, if it
so, whether memory will grow,

can any one please suggest your valuable inputs in this, by how to handle
this type of scenario.


Well, I wouldn't worry about it, personally. The garbage collector is
pretty good, and while it's worth keeping an eye on the memory to be
sure, you'll probably find it isn't a problem.


Yes Jon this is increasing our application memory usage and goes out of
memory exception problem.

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

Jul 21 '05 #3
Sethu,

Because as you, do I try to avoid this kind of code, and normally should the
GC do its work as well with this. If it really that harmful than you can try
to set that global value of course to null to remove the last reference.

Cor
Jul 21 '05 #4
Jon,

Assuming there are no other live references to it, it will be collected
next time the generation it lives in is garbage collected.

This is as well a part of our last discussion about that usng "with events"
nothing to do with the "event". However, done in this way (as I wrote) there
would stay forever a last reference as long as the (a kind of toplevel)
object live. That is the reason why I found it wrong code although it does
work.

Well, I wouldn't worry about it, personally. The garbage collector is
pretty good, and while it's worth keeping an eye on the memory to be
sure, you'll probably find it isn't a problem.

However for me in general it is the same as you wrote above,

Cor
Jul 21 '05 #5
Cor Ligthert <no************@planet.nl> wrote:
Assuming there are no other live references to it, it will be collected
next time the generation it lives in is garbage collected.


This is as well a part of our last discussion about that usng "with events"
nothing to do with the "event". However, done in this way (as I wrote) there
would stay forever a last reference as long as the (a kind of toplevel)
object live. That is the reason why I found it wrong code although it does
work.


I don't see the relationship to the other thread. I'm assuming that in
this case the OP really *does* want to keep track of the last order of
a particular customer, in which case I see nothing wrong with the code
at all.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
I don't recall seeing any recommendations particularly against this
type of code. Could you give a link to the page you're talking about?


the link page is
http://msdn.microsoft.com/library/de...ary/en-us/dnpa
g/html/scalenetchapt05.asp

under the paragraph "Prevent the Promotion of Short-Lived Objects"


Right. Personally, I think that's a very bad example. Unless the Order
class has a significant overhead (which it doesn't appear to) I
wouldn't expect that associating one with a Customer would have
significant problems. There's nothing in the code given to really
indicate that Customer is likely to be a very long-lived object.

Whether or not it's appropriate to use this for your particular code
would depend on your actual situation though - could you give more
details?
Well, I wouldn't worry about it, personally. The garbage collector is
pretty good, and while it's worth keeping an eye on the memory to be
sure, you'll probably find it isn't a problem.


Yes Jon this is increasing our application memory usage and goes out of
memory exception problem.


It sounds very unlikely that this is actually the cause of an out of
memory exception. Have you used a profiler to determine this? What does
your actual code look like?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #7
We have developed a dotnet application running as windows service.

Background: We are running a resource intensive application, which 1)
Maintain huge chunk of in memory data 2) create Assemblies/AppDomain runtime
3) Spawn multiple threads during runtime 4) process request from multiple
sources parallely.

Issue: Out of memory exception errors may occurs even when significant
amounts of physical memory are still available, which makes the application
unstable.

We tested by installing the .NET framework 1.1 Service pack 1(published
8/30/2004), which specifically talks about this problem. But still we are
getting this problem.
"Jon Skeet [C# MVP]" wrote:
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
I don't recall seeing any recommendations particularly against this
type of code. Could you give a link to the page you're talking about?


the link page is
http://msdn.microsoft.com/library/de...ary/en-us/dnpa
g/html/scalenetchapt05.asp

under the paragraph "Prevent the Promotion of Short-Lived Objects"


Right. Personally, I think that's a very bad example. Unless the Order
class has a significant overhead (which it doesn't appear to) I
wouldn't expect that associating one with a Customer would have
significant problems. There's nothing in the code given to really
indicate that Customer is likely to be a very long-lived object.

Whether or not it's appropriate to use this for your particular code
would depend on your actual situation though - could you give more
details?
Well, I wouldn't worry about it, personally. The garbage collector is
pretty good, and while it's worth keeping an eye on the memory to be
sure, you'll probably find it isn't a problem.


Yes Jon this is increasing our application memory usage and goes out of
memory exception problem.


It sounds very unlikely that this is actually the cause of an out of
memory exception. Have you used a profiler to determine this? What does
your actual code look like?

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

Jul 21 '05 #8
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
We have developed a dotnet application running as windows service.

Background: We are running a resource intensive application, which 1)
Maintain huge chunk of in memory data 2) create Assemblies/AppDomain runtime
3) Spawn multiple threads during runtime 4) process request from multiple
sources parallely.

Issue: Out of memory exception errors may occurs even when significant
amounts of physical memory are still available, which makes the application
unstable.

We tested by installing the .NET framework 1.1 Service pack 1(published
8/30/2004), which specifically talks about this problem. But still we are
getting this problem.


If you've still got significant amounts of physical memory available,
this sounds like it could be a .NET bug - it may be worth raising a
problem report with Microsoft directly, particularly if you can
reproduce the problem.

One thing which *might* be happening is that you're running out not of
memory, but of handles (eg file handles). I've a feeling that gets
reported as an out of memory exception too in some situations. Are you
definitely disposing of all unmanaged resources when you've finished
with them?

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


"Jon Skeet [C# MVP]" wrote:
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
We have developed a dotnet application running as windows service.

Background: We are running a resource intensive application, which 1)
Maintain huge chunk of in memory data 2) create Assemblies/AppDomain runtime
3) Spawn multiple threads during runtime 4) process request from multiple
sources parallely.

Issue: Out of memory exception errors may occurs even when significant
amounts of physical memory are still available, which makes the application
unstable.

We tested by installing the .NET framework 1.1 Service pack 1(published
8/30/2004), which specifically talks about this problem. But still we are
getting this problem.
If you've still got significant amounts of physical memory available,
this sounds like it could be a .NET bug - it may be worth raising a
problem report with Microsoft directly, particularly if you can
reproduce the problem.

One thing which *might* be happening is that you're running out not of
memory, but of handles (eg file handles). I've a feeling that gets
reported as an out of memory exception too in some situations. Are you
definitely disposing of all unmanaged resources when you've finished
with them?


Yes Jon Skeet we are properly disposing all of our objects, I have one input
that
we are using one wrapper object for Unmanaged code, inside of it also we are
desposing, my thoughts are whether the unmanaged code call will be properly
disposed.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #10
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
One thing which *might* be happening is that you're running out not of
memory, but of handles (eg file handles). I've a feeling that gets
reported as an out of memory exception too in some situations. Are you
definitely disposing of all unmanaged resources when you've finished
with them?


Yes Jon Skeet we are properly disposing all of our objects, I have
one input that we are using one wrapper object for Unmanaged code,
inside of it also we are desposing, my thoughts are whether the
unmanaged code call will be properly disposed.


What *exactly* do you mean by "whether the unmanaged code code will be
properly disposed"? A call itself doesn't need to be disposed.

It sounds like you could really do with a profiler to find out what's
taking all your memory. Does it fail in different places each time, or
is it always on the same type of call? If it's the latter, that might
suggest a non-memory related problem.

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


"Jon Skeet [C# MVP]" wrote:
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
One thing which *might* be happening is that you're running out not of
memory, but of handles (eg file handles). I've a feeling that gets
reported as an out of memory exception too in some situations. Are you
definitely disposing of all unmanaged resources when you've finished
with them?
Yes Jon Skeet we are properly disposing all of our objects, I have
one input that we are using one wrapper object for Unmanaged code,
inside of it also we are desposing, my thoughts are whether the
unmanaged code call will be properly disposed.


What *exactly* do you mean by "whether the unmanaged code code will be
properly disposed"? A call itself doesn't need to be disposed.

It sounds like you could really do with a profiler to find out what's
taking all your memory. Does it fail in different places each time, or
is it always on the same type of call? If it's the latter, that might
suggest a non-memory related problem.


I am not able to test with the prfiler, because in my application during
runtime i am creating a assemblies i.e. dynamic assemblies, so the profiler
is not able for my application.

We already did some exercise with microsoft supporting team in this, we
asked a dump file when out of memory exception comes, and they analyse this
said that it would be unmanaged component, so we did some fix in that
unmanaged calling wrapper class file. we found some improvement, however we
are still getting this OME problem, is it possible you to analyse the new
dump file, for getting some information.

please let me know any queries/ clarrifications in this.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #12
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
It sounds like you could really do with a profiler to find out what's
taking all your memory. Does it fail in different places each time, or
is it always on the same type of call? If it's the latter, that might
suggest a non-memory related problem.


I am not able to test with the prfiler, because in my application during
runtime i am creating a assemblies i.e. dynamic assemblies, so the profiler
is not able for my application.

We already did some exercise with microsoft supporting team in this, we
asked a dump file when out of memory exception comes, and they analyse this
said that it would be unmanaged component, so we did some fix in that
unmanaged calling wrapper class file. we found some improvement, however we
are still getting this OME problem, is it possible you to analyse the new
dump file, for getting some information.

please let me know any queries/ clarrifications in this.


I'm afraid I don't have the time (or the expertise) to analyse the dump
file. I suggest you go back to the Microsoft support team, I'm afraid.

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


"Jon Skeet [C# MVP]" wrote:
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
It sounds like you could really do with a profiler to find out what's
taking all your memory. Does it fail in different places each time, or
is it always on the same type of call? If it's the latter, that might
suggest a non-memory related problem.
I am not able to test with the prfiler, because in my application during
runtime i am creating a assemblies i.e. dynamic assemblies, so the profiler
is not able for my application.

We already did some exercise with microsoft supporting team in this, we
asked a dump file when out of memory exception comes, and they analyse this
said that it would be unmanaged component, so we did some fix in that
unmanaged calling wrapper class file. we found some improvement, however we
are still getting this OME problem, is it possible you to analyse the new
dump file, for getting some information.

please let me know any queries/ clarrifications in this.


I'm afraid I don't have the time (or the expertise) to analyse the dump
file. I suggest you go back to the Microsoft support team, I'm afraid.


Jon i need a design requriement, can you please able to give some valuable
suggestions in this.

I need to develop a Logger Component in dotnet, It needs to be supported as
ServicedComponent (COM+) to support Business layer components and Library
Reference to support UI Control.

As per my thoughts it should can have some interface which have a method to
logging the error details,

when it is act as a serviced components it should log into database and when
it act as library reference it should log into xm file.

please let me any further clarrifications requried

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

Jul 21 '05 #14
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
I'm afraid I don't have the time (or the expertise) to analyse the dump
file. I suggest you go back to the Microsoft support team, I'm afraid.
Jon i need a design requriement, can you please able to give some valuable
suggestions in this.


Maybe - although this sounds like it belongs in a completely new
thread...
I need to develop a Logger Component in dotnet, It needs to be supported as
ServicedComponent (COM+) to support Business layer components and Library
Reference to support UI Control.

As per my thoughts it should can have some interface which have a method to
logging the error details,

when it is act as a serviced components it should log into database and when
it act as library reference it should log into xm file.

please let me any further clarrifications requried


Well, firstly I'd consider using existing logging interfaces - have a
look at log4net to start with: http://logging.apache.org/log4net/

I suspect that it isn't a good idea to tie the configuration directly
to whether it's being used as a serviced component or not - why not
just configure it appropriately in each setting? That way if you later
need it to log to a database even when you're using it from the UI, you
just need to change the configuration rather than a load of assumptions
made in code.

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


"Jon Skeet [C# MVP]" wrote:
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
I'm afraid I don't have the time (or the expertise) to analyse the dump
file. I suggest you go back to the Microsoft support team, I'm afraid.
Jon i need a design requriement, can you please able to give some valuable
suggestions in this.


Maybe - although this sounds like it belongs in a completely new
thread...
I need to develop a Logger Component in dotnet, It needs to be supported as
ServicedComponent (COM+) to support Business layer components and Library
Reference to support UI Control.

As per my thoughts it should can have some interface which have a method to
logging the error details,

when it is act as a serviced components it should log into database and when
it act as library reference it should log into xm file.

please let me any further clarrifications requried


Well, firstly I'd consider using existing logging interfaces - have a
look at log4net to start with: http://logging.apache.org/log4net/

I suspect that it isn't a good idea to tie the configuration directly
to whether it's being used as a serviced component or not - why not
just configure it appropriately in each setting? That way if you later
need it to log to a database even when you're using it from the UI, you
just need to change the configuration rather than a load of assumptions
made in code.


Your are right my component should act as configured in xml, but my thoughts
is how logger component can support both logging in Service component and
alos in UI controller.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #16
Sethu Madhavan <Se***********@discussions.microsoft.com> wrote:
I suspect that it isn't a good idea to tie the configuration directly
to whether it's being used as a serviced component or not - why not
just configure it appropriately in each setting? That way if you later
need it to log to a database even when you're using it from the UI, you
just need to change the configuration rather than a load of assumptions
made in code.


Your are right my component should act as configured in xml, but my thoughts
is how logger component can support both logging in Service component and
alos in UI controller.


Well, what do you think would be the problem?

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

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

Similar topics

3
by: Christopher Jeris | last post by:
Please help me understand the differences, in semantics, browser support and moral preferredness, between the following three methods of swapping content in and out of a page via JavaScript. I...
0
by: Fiona McBride | last post by:
Hi all, I have a really odd problem with some Visual Basic .NET 2003 code; I have a program that creates a number of windows which contain RichTextBox, Timers (disabled) and menus. The code...
270
by: Jatinder | last post by:
I found these questions on a web site and wish to share with all of u out there,Can SomeOne Solve these Porgramming puzzles. Programming Puzzles Some companies certainly ask for these...
28
by: rajendra.stalekar | last post by:
Hi Folks!!! I have a string let's say "hi" and got to reverse it using just a single variable for swapping, how do I do it? Regards, Rajendra S.
0
by: Fiona McBride | last post by:
Hi all, I have a really odd problem with some Visual Basic .NET 2003 code; I have a program that creates a number of windows which contain RichTextBox, Timers (disabled) and menus. The code...
2
by: Sam Marrocco | last post by:
Does anyone know of a method of swapping collection items? For example: Current collection: ..Item(1)="a" ..Item(2)="b" ..Item(3)="c" After swapping items 2 and 1.... ..Item(1)="b"...
16
by: Sethu Madhavan | last post by:
Hi All Here i am facing one technical issue related to Swapping the Object Instance in Dotnet. e.g.. class Customer{ Order _lastOrder;
1
by: subramanian100in | last post by:
Will the following code always work ? #include <stdio.h> #include <stdlib.h> # define SIZE 50 void myswap(char **name1, char **name2); int main(void)
3
by: Geoff Cox | last post by:
Hello, Way back in 2000 Ken Cox put up this code for swapping images on a button. I cannot work out how to use it so that more than 1 button can use it. I guess the problem is knowing how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.