Heap Views in Visual Studio - Mark Downie
文章推薦指數: 80 %
The Diagnostic Tool is at its best when you want to compare things over time, like say when memory increases or when in CPU usage fluctuates ... Blog Category Archive About Subscribe Thiswebsiteusescookiestoensureyougetthebestexperienceonourwebsite.LearnMore. Accept HeapViewsinVisualStudio May06,2020 TaggedinDiagnostics,VisualStudio Comments[0] SoIlovetheideathatdevelopersshouldfocusontheabstractionlayerthatmakesthemproductiveandhappy,evenifothersdisagree.Ialsobelieveitismyjobtoencourageexplorationorevenhelpfillthegapsinlayersaboveyouthatmightassistothers.WiththatinmindthereisanincrediblyusefulviewoftheGCHeapinVisualStudiothatIwanttoremindpeopleabout.Itallowsyoutoseememorygrowthrelatedtotheheap.However,ittakesalittlediggingtofindit.GotoDebug->Windows->DiagnosticsTools.TheDiagnosticToolisatitsbestwhenyouwanttocomparethingsovertime,likesaywhenmemoryincreasesorwheninCPUusagefluctuatesbutisstillveryhelpfulforspecificmomentsintime.Soifyouwanttotakealookattheheap,andIdo,youcannavigatetotheMemoryUsagetabandclickontheTakeSnapshot.ThistakesapictureoftheheapandoncestoredyoucansimplyclickViewHeap.InthefirstimageIhavetakenaSnapshotatthetwobreakpointsTheSnapshotgivesshowsalistviewofallthemanagedobjectsontheheap.NowinprecedingSnapshotofaverysimplecommandlineapptherearejusttwoclasses,butnoticetherealreadyseemstobethreespecificexceptionobjectsalreadyontheStack(OutOfMemoryException,StackOverflowException,ExecutionEngineException).Infacttheseexceptionsexisteverytimeamanagedprocessstartsup,soifyouweretolookatanymanagedmemorydumpusingWinDbgandsayrun!dumpheap-typeExceptionyouwouldseetheexactsamething.Why?Wellthesethreeexceptionswouldimpossibletoaddtotheheapafterthefact,thinkaboutanOutOfMemoryException,bydefinitionyouwouldnotbeabletoaddanythingelsetotheheap.TocircumventthistheCLRgeneratestheseexceptionobjectsatstartupsothatitcanthrowthemwhenevertherealexceptionoccurs.Sowhenyouseethesethreeexceptionswithacountof1donotworryitsprobablynotyourcodecausingit.FilteringtheManagedHeapYoucanfilteroutobjectsontheheaptohelpyoufocusonthethemostimportantorinterestingobjects,therearecurrentlyonlytwooption“JustMyCode”and“CollapseSmallObjectTypes”.TheJustMyCodefilter'folds'alistofobjectsintotheirparentobjects,theyessentiallybecomehiddenandtheirsizeisaddedtotheparentobjects.Thelistwasconstructedbasedonsomecommonleakpatterns,forexampleifyouhaveaneventhandlerleak,withoutthissetting,youwillseeinterimnodesofvariousinternal.NETobjectsbetweenthesubscriberandtheobjectraisingtheevent,makingitreallydifficulttospotthetruesourceoftheleak.FilteringobjectslikeSystem.Windows.EventHandlersStore,System.StringsandSystem.Objectsputsyourfocusontheobjectallocatingandholdingontomoreresourcesthantheyneed.CollapseSmallObjectTypesisabitmoredirectinthatitlooksattheoverallsizeoftheManagedHeapandonceselecteditremovesanygroupofobjectsthattakeuplessthan0.5%(bydefault)ofthetotalheap,again,thisreallyhelpsfilterthenoise.ComparingHeapsThisiswheretheDiagnosticsToolsshinesyoucancompareacoupleofsnapshotsandseewhereunexpectedmemorygrowthisoccurring.Oneotherthingtorememberhereisthatalltheseviewsarealsoavailablefordumps,soifyoucapturetwodumpsfromthesameprocessyoucanvalidatewhetheryouareseeinggrowthonanyheapobjectbydroppingthembothinVisualStudio. ShareonTwitterFacebookLinkedIn CommentSection Commentsareclosed. Aboutus Iworkasatechnicalleadinthefieldofsoftwareengineeringanddevelopment,withexpertiseinfinancialservices,healthcareandmanufacturing.Moredetailshere. GetinTouch Pages Home Blog Category Archive About Subscribe SubscribetomyRSSfeedtoalwaysgetthelatestupdates. ©2022-MarkDownie,AllRightsReserved. PoweredbyDasblog-Corecommit0f0859
延伸文章資訊
- 1Increasing the JVM heap size for XDE for Java - IBM
A Microsoft Visual C++ Runtime Library error occurs when using IBM® Rational® XDE™ for Java™ inte...
- 2Why does Visual C++ has a limited stack and heap allocation ...
In visual studio, on the linker option there are bot Stack and Heap reserve Size, both are set to...
- 3Heap Views in Visual Studio - Mark Downie
The Diagnostic Tool is at its best when you want to compare things over time, like say when memor...
- 4VS 2017 C++Compiler runs out of heap space
Both 32-bit and 64-bit configurations compile and eventually run out of heap space. Visual Studio...
- 5Visual Studio 16.7 reporting compiler is out of heap space ...
When compiling a Visual C++ project that successfully compiled under Visual Studio MSVC 16.6 yest...