Unity Heap Crawler
Public Member Functions | Public Attributes | List of all members
UnityHeapCrawler.HeapSnapshotCollector Class Reference

Tool for crawling mono heap and collecting memory usage. More...

Public Member Functions

HeapSnapshotCollector AddRoot ([NotNull] object root, [NotNull] string name)
 
HeapSnapshotCollector AddRootTypes ([NotNull] params Type[] types)
 
HeapSnapshotCollector AddForbiddenTypes ([NotNull] params Type[] types)
 
HeapSnapshotCollector AddStaticTypes ([NotNull] params Type[] types)
 
HeapSnapshotCollector AddTrackedTypes ([NotNull] params Type[] types)
 
CrawlSettings AddRootsGroup ([NotNull] string filename, [NotNull] string caption, CrawlOrder order, params object[] roots)
 
CrawlSettings AddUnityRootsGroup< T > ([NotNull] string filename, [NotNull] string caption, CrawlOrder order)
 
HeapSnapshotCollector SetMinTypeSize (int size)
 
HeapSnapshotCollector SetSizeFormat (SizeFormat format)
 
void Start ()
 Let The Crawling Begin! More...
 

Public Attributes

readonly CrawlSettings UserRootsSettings
 CrawlSettings for user defined roots. More...
 
readonly CrawlSettings StaticFieldsSettings
 CrawlSettings for static fields in all types. More...
 
readonly CrawlSettings HierarchySettings
 CrawlSettings for GameObjects in scene hierarchy. More...
 
readonly CrawlSettings ScriptableObjectsSettings
 CrawlSettings for all ScriptableObjects.
More...
 
readonly CrawlSettings PrefabsSettings
 CrawlSettings for all loaded Prefabs. More...
 
readonly CrawlSettings UnityObjectsSettings
 CrawlSettings for all other Unity objects (Texture, Material, etc).
More...
 
bool DifferentialMode = true
 Only show new objects (compared to previous snapshot) in all reports More...
 

Detailed Description

Tool for crawling mono heap and collecting memory usage.

  1. Analyze managed memory consumption prior to reducing it
  2. Locate managed memory leaks.

Member Function Documentation

◆ AddForbiddenTypes()

HeapSnapshotCollector UnityHeapCrawler.HeapSnapshotCollector.AddForbiddenTypes ( [NotNull] params Type []  types)

Forbid some types to be crawled. Crawler will not follow links to instances of those types or count them to total size.

Useful when you need to collect only a local snapshot from custom definded roots without triggering whole heap to be crawled. Also can be useful to reduce memory consumption by crawling only a part of the heap.

Parameters
typesForbidden types
Returns

◆ AddRoot()

HeapSnapshotCollector UnityHeapCrawler.HeapSnapshotCollector.AddRoot ( [NotNull] object  root,
[NotNull] string  name 
)

Add custom root. It will be crawled before any other objects.

It should be useful to add your big singletons as custom roots.

Parameters
rootRoot to crawl (C# object instance)
nameRoot name in report
Returns

◆ AddRootsGroup()

CrawlSettings UnityHeapCrawler.HeapSnapshotCollector.AddRootsGroup ( [NotNull] string  filename,
[NotNull] string  caption,
CrawlOrder  order,
params object []  roots 
)

Add custom roots crawling group. Results will be wrtitten to a seperate file.

Explicit objects version.

Parameters
filenameFilename for group output
captionGroup caption
orderCrawling priority
rootsRoot objects
Returns
Crawl settings for further configuration

◆ AddRootTypes()

HeapSnapshotCollector UnityHeapCrawler.HeapSnapshotCollector.AddRootTypes ( [NotNull] params Type []  types)

Add root types.

Objects of these types will be treated as roots and will not be included into crawl trees they were found in.

Parameters
typesRoot types
Returns

◆ AddStaticTypes()

HeapSnapshotCollector UnityHeapCrawler.HeapSnapshotCollector.AddStaticTypes ( [NotNull] params Type []  types)

Add additional types to check for static fields and add them as roots.

This is a workaround for an unsupported case. Consider following class:

class GenericClass<T> { public static List<T> StaticList; }

Static fields GenericClass<A>.StaticList and GenericClass<B>.StaticList would be different lists that should both be counted as roots. Crawler cannot find those roots automatically due to C# Reflection limitations.

Parameters
typesForbidden types
Returns

◆ AddTrackedTypes()

HeapSnapshotCollector UnityHeapCrawler.HeapSnapshotCollector.AddTrackedTypes ( [NotNull] params Type []  types)

Enable root paths tracking for specific types.

Can affect memory consumption - for each instance of specified types all root paths to it will be logged. Useful when you already know exact type is leaked and need to find what is holding it.

Parameters
typesTypes to track
Returns

◆ AddUnityRootsGroup< T >()

CrawlSettings UnityHeapCrawler.HeapSnapshotCollector.AddUnityRootsGroup< T > ( [NotNull] string  filename,
[NotNull] string  caption,
CrawlOrder  order 
)

Add custom roots crawling group. Results will be wrtitten to a seperate file.

All Unity objects of specified type are included in the group.

Parameters
filenameFilename for group output
captionGroup caption
orderCrawling priority
Returns
Crawl settings for further configuration

◆ SetMinTypeSize()

HeapSnapshotCollector UnityHeapCrawler.HeapSnapshotCollector.SetMinTypeSize ( int  size)

Set minimum size for type to be included in types report.

All instances of the type should be at least this size total for type to be included in type report.

Parameters
sizeMinimum size type
Returns

◆ SetSizeFormat()

HeapSnapshotCollector UnityHeapCrawler.HeapSnapshotCollector.SetSizeFormat ( SizeFormat  format)

Set sizes format in output.

Short 54.8 MB

Precise 54829125

Combined 54.8 MB (54829125)

Parameters
format
Returns

◆ Start()

void UnityHeapCrawler.HeapSnapshotCollector.Start ( )

Let The Crawling Begin!

Member Data Documentation

◆ DifferentialMode

bool UnityHeapCrawler.HeapSnapshotCollector.DifferentialMode = true

Only show new objects (compared to previous snapshot) in all reports

Useful to find memory leaks

◆ HierarchySettings

readonly CrawlSettings UnityHeapCrawler.HeapSnapshotCollector.HierarchySettings

CrawlSettings for GameObjects in scene hierarchy.

Modify them after construction to change output format or disable crawling. Be careful when reducing filtering - large crawl trees will affect memory consumption.

◆ PrefabsSettings

readonly CrawlSettings UnityHeapCrawler.HeapSnapshotCollector.PrefabsSettings

CrawlSettings for all loaded Prefabs.

Modify them after construction to change output format or disable crawling. Be careful when reducing filtering - large crawl trees will affect memory consumption.

◆ ScriptableObjectsSettings

readonly CrawlSettings UnityHeapCrawler.HeapSnapshotCollector.ScriptableObjectsSettings

CrawlSettings for all ScriptableObjects.

Modify them after construction to change output format or disable crawling. Be careful when reducing filtering - large crawl trees will affect memory consumption.

◆ StaticFieldsSettings

readonly CrawlSettings UnityHeapCrawler.HeapSnapshotCollector.StaticFieldsSettings

CrawlSettings for static fields in all types.

Modify them after construction to change output format or disable crawling. Be careful when reducing filtering - large crawl trees will affect memory consumption.

◆ UnityObjectsSettings

readonly CrawlSettings UnityHeapCrawler.HeapSnapshotCollector.UnityObjectsSettings

CrawlSettings for all other Unity objects (Texture, Material, etc).

Modify them after construction to change output format or disable crawling. Be careful when reducing filtering - large crawl trees will affect memory consumption.

◆ UserRootsSettings

readonly CrawlSettings UnityHeapCrawler.HeapSnapshotCollector.UserRootsSettings

CrawlSettings for user defined roots.

Modify them after construction to change output format or disable crawling. Be careful when reducing filtering - large crawl trees will affect memory consumption.


The documentation for this class was generated from the following file: