473,320 Members | 2,006 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,320 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 1576
<"=?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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.