Heap Views in Visual Studio - Mark Downie

文章推薦指數: 80 %
投票人數:10人

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



請為這篇文章評分?