Sample questions
Un Csharp Memory Gc PerformanceDifficulty 1
In the Unity Profiler's CPU Usage module, what does the "GC Alloc" column for a given frame show?
- aThe total size of the managed heap reserved by the runtime.
- bThe amount of managed memory script code allocated during that frame.✓
- cThe amount of native (C++) memory Unity's engine allocated that frame.
- dThe number of garbage collection passes that ran since the app started.
Explanation:"GC Alloc" reports how much managed memory your script code allocated in that specific frame, which is the number to watch when hunting per-frame allocations in Update.
Un Csharp Memory Gc PerformanceDifficulty 1
In C#, when a struct variable is assigned to another struct variable, what happens?
- aThe full value is copied; the two copies are independent.✓
- bBoth variables end up referencing the same memory location on the heap.
- cOnly a pointer to the original struct is stored in the new variable.
- dThe assignment allocates a new object on the managed heap automatically.
Explanation:A struct is a value type, so assignment copies its full contents; the source and destination are independent, unlike reference types which share the same heap object.
Un Csharp Memory Gc PerformanceDifficulty 1
In Unity's Mono scripting backend, when is your C# script code compiled into machine code?
- aEntirely during the Unity Editor's asset import step, before any build exists.
- bNever — Mono interprets the C# bytecode line by line at every call.
- cAt runtime, just-in-time, as the IL executes on the device.✓
- dAhead of time, by translating the IL into C++ during the build.
Explanation:Mono is a just-in-time (JIT) runtime: it compiles the intermediate language to machine code as the app runs, rather than translating it to native code ahead of time like IL2CPP does.
Un Csharp Memory Gc PerformanceDifficulty 1
In UnityEngine, what kind of C# type is Vector3?
- aAn abstract class that concrete vector implementations inherit from.
- bA sealed reference class allocated on the managed heap on creation.
- cAn interface implemented separately by each supported platform's math library.
- dA struct — a value type stored inline, not on the managed heap.✓
Explanation:Vector3 (like Quaternion and most UnityEngine math types) is a struct: a value type, so passing or copying it does not by itself allocate on the managed heap.
Un Csharp Memory Gc PerformanceDifficulty 1
What is the main practical difference between Physics.RaycastAll and Physics.RaycastNonAlloc?
- aRaycastNonAlloc writes hits into an array you supply, instead of allocating a new array.✓
- bRaycastNonAlloc can detect colliders on a different physics layer than RaycastAll.
- cRaycastAll runs on a background thread while RaycastNonAlloc always runs on the main thread.
- dRaycastNonAlloc ignores trigger colliders entirely, while RaycastAll always includes them.
Explanation:Physics.RaycastAll allocates and returns a new RaycastHit[] every call. Physics.RaycastNonAlloc instead fills a RaycastHit[] buffer you pass in, so calling it repeatedly (e.g. every frame) produces no garbage.
Un Csharp Memory Gc PerformanceDifficulty 1
Why does a NativeArray<T> require you to call Dispose() manually, unlike a regular managed array?
- aNativeArray<T> is actually a managed array under the hood, but with a stricter API.
- bNativeArray<T> wraps unmanaged memory that lives outside the garbage collector's control.✓
- cCalling Dispose() is only a style convention; the runtime frees it anyway at frame end.
- dNativeArray<T> memory is automatically freed the moment the array goes out of scope.
Explanation:NativeArray<T> allocates unmanaged (native) memory using an Allocator. The garbage collector never tracks or frees it, so the memory stays reserved until you explicitly call Dispose().