在点网中交换对象实例 [英] Swapping the object instance in dot net

查看:63
本文介绍了在点网中交换对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


在这里,我面临一个与交换对象实例相关的技术问题
Dotnet中的



例如。


级客户{


订单_lastOrder;


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

订购currentOrder =新订单(ID,数量,金额,产品ID);


currentOrder.Insert();


this._lastOrder = currentOrder


}

这是我的班级,当我尝试将currentOrder实例交换到
_lastOrder时,currentOrder对象内存会发生什么,无论是
会立即销毁还是什么阶段。根据Microsoft

建议避免使用这种类型的代码,因为它增加了在Gen 0之外提升

对象的可能性,这会延迟对象的资源来自<回收



我经常在我的应用程序中使用这种类型的交换,如果它是
那么,是否内存将会增长,


任何人都可以在此建议您的宝贵意见,如何处理

此类情景。

解决方案

<" =?Utf-8?B?U2V0aHUgTWFkaGF2YW4 =?=" < Sethu
Ma******@discussions.microsoft.com >>写道:

这里我面临一个与在Dotnet中交换对象实例相关的技术问题。

例如。

类客户{

订单_lastOrder;

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

订单currentOrder = new Order(ID ,数量,金额,产品ID);

currentOrder.Insert();

this._lastOrder = currentOrder

}

这是我的类,当我尝试将currentOrder实例交换到
_lastOrder时,currentOrder对象内存会发生什么,无论是
会立即销毁还是什么阶段。


假设没有其他的实时参考,它将被收集

下一次它生成的一代是垃圾收集。

根据微软的建议,避免使用这种类型的代码,因为它增加了对象被提升超过Gen 0的可能性,这延迟了对象的资源被回收。


我不记得看到任何特别反对这种

类型代码的建议。你能给出你正在谈论的页面的链接吗?

我经常在我的应用程序中使用这种类型的交换,如果它,那么,内存是否会增长,

任何人都可以在此建议您的宝贵意见,如何处理这种情况。




好​​吧,我个人而言,我不担心。垃圾收集器非常好,虽然值得关注内存,但是你肯定会发现它不是'''''''''''''''''''''''''''''' ta问题。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件





" Jon Skeet [C#MVP]"写道:

<" =?Utf-8?B?U2V0aHUgTWFkaGF2YW4 =?=" < Sethu
Ma******@discussions.microsoft.com >>写道:

这里我面临一个与在Dotnet中交换对象实例相关的技术问题。

例如。

类客户{

订单_lastOrder;

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

订单currentOrder = new Order(ID ,数量,金额,产品ID);

currentOrder.Insert();

this._lastOrder = currentOrder

}

这是我的班级,当我尝试将currentOrder实例交换到
_lastOrder时,currentOrder对象内存会发生什么,无论是
会立即销毁还是什么阶段。
假设没有其它的实时引用,它将被收集
下一次它生成的一代是垃圾收集。

根据微软的建议避免这种类型的代码,因为它增加了对象被提升到第0代以外的可能性,
会延迟对象的资源被回收。



我不记得看到任何特别针对这种代码类型的建议。你能给出你正在谈论的页面的链接吗?




链接页面是
http://msdn.microsoft.com/library/ de ... netchapt05.asp


段落预防短生物的促销

< blockquote class =post_quotes>我在我的应用程序中非常频繁地使用这种类型的交换,如果它,那么,内存是否会增长,

任何人都可以建议你的宝贵输入这个,通过如何处理这种情况。



好吧,我个人也不担心。垃圾收集器非常好,虽然值得关注内存是肯定的,但你可能会发现它不是问题。




是的Jon这会增加我们的应用程序内存使用量,并且会出现内存异常问题。

-
Jon Skeet - < sk *** @ pobox.com>
http:/ /www.pobox.com/~skeet
如果回复小组,请不要给我发邮件



Sethu,


因为和你一样,我是否试图避免使用这种代码,并且通常应该使用这个代码来完成它的工作。如果真的那么有害你可以尝试

设置当然全局值为null以删除最后一个引用。


Cor

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.

解决方案

<"=?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




"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



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


这篇关于在点网中交换对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆