コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Rider】「Heap Allocations Viewer」を導入すると割り当てが発生しているコードに下線が表示されるようになる

はじめに

「Heap Allocations Viewer」を Rider に導入すると
割り当てが発生しているコードに下線が表示されるようになるので
自分が知らなかった割り当ての存在を知ることができます

この記事では、どのようなコードがハイライトされるようになるか紹介していきます

目次

導入方法

f:id:baba_s:20190910212606p:plain

Rider メニューの「File > Settings」を選択して

f:id:baba_s:20190910212609p:plain

「Plugins」内の「Marketplace」を押して
検索欄に「Heap Allocations Viewer」と入力して
表示された Heap Allocations Viewer を選択して「Install」を押します
そして、インストールが完了したら「Save」を押して
Rider を再起動すると導入が完了です

f:id:baba_s:20190910212616p:plain

もしも「Plugins」内の「Marketplace」に
Heap Allocations Viewer が見つからなかった場合は
「Installed」を押して検索欄に「Heap Allocations Viewer」と入力して
表示された Heap Allocations Viewer を選択して「Enable」を押します
そして、「Save」を押して Rider を再起動すると導入が完了です

ハイライト表示されるコード

値型を object 型に変換

Boxing allocation: conversion from value 'XXXX' to reference type 'object'

f:id:baba_s:20190910213950p:plain

char 型を object 型に変換

Boxing allocation: conversion from value 'char' to reference type 'object'

f:id:baba_s:20190910213931p:plain

値型で System.Object の仮想関数を呼び出し

Boxing allocation: inerited System.Object virtual method call on value type instance

f:id:baba_s:20190910214023p:plain

f:id:baba_s:20190910214028p:plain

f:id:baba_s:20190910214033p:plain

値型をインターフェイスに変換

Boxing allocation: conversion from value type 'XXXX' to reference type 'YYYY'

f:id:baba_s:20190910214042p:plain

デリゲートの割り当て

Delegate allocation: from method group

f:id:baba_s:20190910214049p:plain

参照型のインスタンスの作成

Object allocation: refeerence type creation

f:id:baba_s:20190910214219p:plain

配列の作成

Object allocation: array creation

f:id:baba_s:20190910214215p:plain

文字列の連結

Object allocation: string concatenation

f:id:baba_s:20190910205536p:plain

列挙子の割り当て

Possible object allocation: enumerator allocation (except iterators or collection with cached enumerator)

f:id:baba_s:20190910205538p:plain

デリゲートで this 参照をキャプチャ

Delegate allocation: capture of 'this' reference

f:id:baba_s:20190910205541p:plain

クロージャの割り当て

Closure allocation

f:id:baba_s:20190910205544p:plain

LINQ の呼び出し

Object allocation: LINQ method call

f:id:baba_s:20190910205547p:plain