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...
- 2HEAP (設定堆積大小)
以十進位或C 語言標記法指定保留和 commit 值。 這項功能也可透過具有HEAPSIZE的模組定義檔來使用。 在Visual Studio 開發環境中設定這個連結器選項.
- 3How to increase the maximum memory allocated on the stack ...
- 4Visual 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...
- 5VS 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...