C# “什么可以?”;Pin";Silverlight中的内存对象?
我正在调试一个似乎疯狂地泄漏内存的应用程序;大部分似乎是由于固定对象(在可写位图中下载的图像数据)的碎片造成的。然而,我并不是故意使用GC.Handle或类似的东西。我所做的就是将数据存储在C# “什么可以?”;Pin";Silverlight中的内存对象?,c#,silverlight,clr,windbg,C#,Silverlight,Clr,Windbg,我正在调试一个似乎疯狂地泄漏内存的应用程序;大部分似乎是由于固定对象(在可写位图中下载的图像数据)的碎片造成的。然而,我并不是故意使用GC.Handle或类似的东西。我所做的就是将数据存储在内存流中,然后像这样引用它 什么操作会将数据固定在内存中,而不会显式地这么说?另外,如何使用WinDbg找到固定它的内容 编辑:对于每个请求,这里是一个!GCRoot位于System.Int32阵列上,与一大块可用内存相邻。这是所有大型自由块的代表 编辑2:在与我的新朋友WinDbg和SOS相处了一段时间后,
内存流中,然后像这样引用它
什么操作会将数据固定在内存中,而不会显式地这么说?另外,如何使用WinDbg找到固定它的内容
编辑:对于每个请求,这里是一个!GCRoot位于System.Int32阵列上,与一大块可用内存相邻。这是所有大型自由块的代表
编辑2:在与我的新朋友WinDbg和SOS相处了一段时间后,我发现WriteableBitmaps
和MemoryStream
对象都是“固定的”,应该小心分配,以防止内存碎片。阅读接受答案中的文章,解释为什么需要这样做
DOMAIN(1AC72358):HANDLE(Pinned):72c12f8:Root: 174c5e20(System.Object[])->
16533060(Project.ProjectParts.PartContainer)->
167fe554(Project.ProjectParts.Part.PartActivity)->
167d21d8(Project.ProjectParts.Sprites.Graphic)->
16770f28(System.Windows.Controls.Canvas)->
16770e1c(System.Windows.Controls.Canvas)->
16770ee4(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
1680e778(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
16770f9c(System.Windows.Controls.Canvas)->
16819114(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
16819160(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
16818df4(System.Windows.Controls.Canvas)->
16818e58(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
16819f10(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
168194c4(System.Windows.Controls.Canvas)->
16819528(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
16819574(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
16819370(System.Windows.Controls.Image)->
21c82138(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
21c82184(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
168195dc(System.Windows.Media.Imaging.WriteableBitmap)->
21c7ce2c(System.Int32[])
DOMAIN(1AC72358):HANDLE(AsyncPinned):72c1dfc:Root: 166bae48(System.Threading.OverlappedData)->
1654d448(System.Threading.IOCompletionCallback)->
1654c29c(System.Net.Sockets.SocketAsyncEventArgs)->
1654bad4(System.Net.Sockets.Socket+StaticConnectAsyncState)->
1654ba40(System.Net.Sockets.SocketAsyncEventArgs)->
1654b684(System.ServiceModel.Channels.SocketConnectionInitiator+ConnectAsyncResult)->
1654b414(System.ServiceModel.Channels.ConnectionPoolHelper+EstablishConnectionAsyncResult)->
1654b3b0(System.ServiceModel.Channels.ClientFramingDuplexSessionChannel+OpenAsyncResult)->
1654b380(System.ServiceModel.Channels.CommunicationObject+OpenAsyncResult)->
1654b330(System.ServiceModel.Channels.CommunicationObject+OpenAsyncResult)->
1654b0f4(System.ServiceModel.Channels.ServiceChannel+SendAsyncResult)->
1654b070(System.ServiceModel.ClientBase`1+AsyncOperationContext[[Cassandra.Common.WCF.IAsyncWcfRequestProcessor, Cassandra.Common.Silverlight]])->
1654b05c(System.ComponentModel.AsyncOperation)->
1654b04c(Project.Common.IoC.InvokeAsyncCompletedEventRequestsArgs)->
1654afec(System.Action`1[[Project.Common.IoC.ProcessRequestsAsyncCompletedArgsEx, Project.Common.SL]])->
1654afc8(Project.Common.IoC.AsyncRequestDispatcherEx+<>c__DisplayClass1)->
1654afa0(Project.Common.IoC.NetResponseReceiver)->
1653408c(System.Action`2[[Cassandra.Common.ExceptionInfo, Cassandra.Common.Silverlight],[Cassandra.Common.ExceptionType, Cassandra.Common.Silverlight]])->
16533ffc(Project.ProjectParts.ILE.Services.EngineProxyService+<>c__DisplayClass5)->
16533fdc(System.Action`1[[Cassandra.Common.ReceivedResponses, Cassandra.Common.Silverlight]])->
16533fbc(Project.ProjectParts.ILE.Services.IEngineProxyExtensions+<>c__DisplayClass1`2[[Project.Services.RequestsAndResponses.ListMediaServersByTokenRequest, Project.Services.RequestsAndResponses.Silverlight],[Project.Services.RequestsAndResponses.ListInstitutionMediaServersResponse, Project.Services.RequestsAndResponses.Silverlight]])->
16533f9c(System.Action`1[[Project.Services.RequestsAndResponses.ListInstitutionMediaServersResponse, Project.Services.RequestsAndResponses.Silverlight]])->
1650a2a0(Project.ProjectParts.ILE.MainPage)->
1674ea0c(Project.ProjectParts.ActivityTimer)->
165330a4(Project.ProjectParts.PauseManager)->
165330bc(System.Collections.Generic.List`1[[Project.ProjectParts.IPausable, ActivityFramework]])->
166a8610(System.Object[])->
167ca858(Project.ProjectParts.ActivityTimer)->
167ca838(Project.ProjectParts.ActivityTimerEventHandler)->
16533060(Project.ProjectParts.PartContainer)->
167fe554(Project.ProjectParts.Part.PartActivity)->
167d21d8(Project.ProjectParts.Sprites.Graphic)->
16770f28(System.Windows.Controls.Canvas)->
16770e1c(System.Windows.Controls.Canvas)->
16770ee4(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
1680e778(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
16770f9c(System.Windows.Controls.Canvas)->
16819114(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
16819160(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
16818df4(System.Windows.Controls.Canvas)->
16818e58(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
16819f10(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
168194c4(System.Windows.Controls.Canvas)->
16819528(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
16819574(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
16819370(System.Windows.Controls.Image)->
21c82138(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
21c82184(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
168195dc(System.Windows.Media.Imaging.WriteableBitmap)->
21c7ce2c(System.Int32[])
DOMAIN(1AC72358):HANDLE(Pinned):72c2b18:Root: 21c7ce2c(System.Int32[])
DOMAIN(1AC72358):句柄(固定):72c12f8:Root:174c5e20(System.Object[])->
16533060(Project.ProjectParts.PartContainer)->
167fe554(Project.ProjectParts.Part.PartActivity)->
167d21d8(Project.ProjectParts.Sprites.Graphic)->
16770f28(System.Windows.Controls.Canvas)->
16770e1c(System.Windows.Controls.Canvas)->
16770ee4(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]])->
1680e778(System.Collections.Generic.Dictionary`2+条目[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]]]]]->
16770f9c(System.Windows.Controls.Canvas)->
16819114(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]])->
16819160(System.Collections.Generic.Dictionary`2+条目[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]][])->
16818df4(System.Windows.Controls.Canvas)->
16818e58(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]])->
16819f10(System.Collections.Generic.Dictionary`2+条目[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]]]]]->
168194c4(System.Windows.Controls.Canvas)->
16819528(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]])->
16819574(System.Collections.Generic.Dictionary`2+条目[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]][])->
16819370(System.Windows.Controls.Image)->
21c82138(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]])->
21c82184(System.Collections.Generic.Dictionary`2+条目[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]]]]]->
168195dc(System.Windows.Media.Imaging.WriteableBitmap)->
21c7ce2c(System.Int32[]
域(1AC72358):句柄(异步固定):72c1dfc:Root:166bae48(System.Threading.OverlappedData)->
1654d448(System.Threading.IOCompletionCallback)->
1654c29c(System.Net.Sockets.SocketAsyncEventArgs)->
1654bad4(System.Net.Sockets.Socket+StaticConnectAsyncState)->
1654ba40(System.Net.Sockets.SocketAsyncEventArgs)->
1654b684(System.ServiceModel.Channel.SocketConnectionInitiator+ConnectAsyncResult)->
1654b414(System.ServiceModel.Channel.ConnectionPoolHelper+EstablishConnectionAsyncResult)->
1654b3b0(System.ServiceModel.Channel.ClientFramingDuplexSessionChannel+OpenAsyncResult)->
1654b380(System.ServiceModel.Channel.CommunicationObject+OpenAsyncResult)->
1654b330(System.ServiceModel.Channel.CommunicationObject+OpenAsyncResult)->
1654b0f4(System.ServiceModel.Channels.ServiceChannel+SendAsyncResult)->
1654b070(System.ServiceModel.ClientBase`1+AsyncOperationContext[[Cassandra.Common.WCF.IAsyncWcfRequestProcessor,Cassandra.Common.Silverlight]])->
1654b05c(System.ComponentModel.AsyncOperation)->
1654b04c(Project.Common.IoC.InvokeAsyncCompletedEventRequestsArgs)->
1654afec(System.Action`1[[Project.Common.IoC.ProcessRequestsSyncCompletedArgSex,Project.Common.SL]])->
1654afc8(Project.Common.IoC.AsyncRequestDispatcherEx+c__DisplayClass1)->
1654afa0(Project.Common.IoC.NetResponseReceiver)->
1653408c(System.Action`2[[Cassandra.Common.ExceptionInfo,Cassandra.Common.Silverlight],[Cassandra.Common.ExceptionType,Cassandra.Common.Silverlight]]->
16533ffc(Project.ProjectParts.ILE.Services.EngineProxyService+c__DisplayClass5)->
16533fdc(System.Action`1[[Cassandra.Common.ReceivedResponses,Cassandra.Common.Silverlight]])->
16533fbc(Project.ProjectParts.ILE.Services.IEngineProxyExtensions+c__DisplayClass1`2[[Project.Services.RequestsAndResponses.ListMediaServersByTokenRequest,Project.Services.RequestsAndResponses.Silverlight],[Project.Services.RequestsAndResponses.ListInstitutionMediaServersResponse,Project.Services.RequestsAndResponses.Silverlight])->>
16533f9c(System.Action`1[[Project.Services.RequestsAndResponses.ListInstitutionMediaServersResponse,Project.Services.RequestsAndResponses.Silverlight]])->
1650a2a0(Project.ProjectParts.ILE.MainPage)->
1674ea0c(Project.ProjectParts.ActivityTimer)->
165330a4(Project.ProjectParts.PauseManager)->
165330bc(System.Collections.Generic.List`1[[Project.ProjectParts.ipaausable,ActivityFramework]])->
166a8610(System.Object[])->
167ca858(Project.ProjectParts.ActivityTimer)->
167ca838(Project.ProjectParts.ActivityTimerEventHandler)->
16533060(Project.ProjectParts.PartContainer)->
167fe554(Project.ProjectParts.Part.PartActivity)->
167d21d8(Project.ProjectParts.Sprites.Graphic)->
16770f28(System.Windows.Controls.Canvas)->
16770e1c(System.Windows.Controls.Canvas)->
16770ee4(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase,System.Windows],[System.Object,mscorlib]])->
1680e778(系统.集合.通用.字典'2+条目[[MS]