void CollectGarbageOnDemand() { if (!UIWidgetsGlobalConfiguration.EnableIncrementalGC) { return; } var mem = Profiler.GetMonoUsedSizeLong(); if (mem < lastFrameMemory) { // GC happened. nextCollectAt = mem + kCollectAfterAllocating; } else if (mem >= nextCollectAt) { // Trigger incremental GC GarbageCollector.GCMode = GarbageCollector.Mode.Enabled; GarbageCollector.CollectIncremental(1000); lastFrameMemory = mem + kCollectAfterAllocating; GarbageCollector.GCMode = GarbageCollector.Mode.Disabled; } lastFrameMemory = mem; }
private void ShootGun(Transform activeRig, Item equipedWeapon) { GarbageCollector.CollectIncremental((ulong)0.1f); gunReloadController = equipedWeapon.GetComponent <GunReloadController>(); if (InventoryManager.Instance.MenuOpen || gunReloadController.isReloading) { return; } SetGunData(activeRig, equipedWeapon); //recoilUpKick = Random.Range(1, (float)recoilUpKick); recoilSideKick = Random.Range(-recoilSideKick, recoilSideKick); bulletDropOff = bulletDrop; //sets data for projectiles dropoff method if (Input.GetKey(KeyCode.Mouse0) && Time.time >= timeToFire && isAutomatic && gunReloadController.currentHoldingAmmo > 0) { timeToFire = Time.time + 1f / fireRate; bulletInstance = ShootBullet(equipedWeapon, bullet.name, shell, shellEjectPoint, shootPoint, facingDir, forceMultiplier, shootSounds, recoilUpKick, recoilSideKick); bulletInstance.GetComponent <Projectile>().InitializeBullet(bulletDamage); return; } else if (Input.GetKeyDown(KeyCode.Mouse0) && Time.time >= timeToFire && gunReloadController.currentHoldingAmmo > 0) { timeToFire = Time.time + 1f / fireRate; bulletInstance = ShootBullet(equipedWeapon, bullet.name, shell, shellEjectPoint, shootPoint, facingDir, forceMultiplier, shootSounds, recoilUpKick, recoilSideKick); bulletInstance.GetComponent <Projectile>().InitializeBullet(bulletDamage); } }
public static void Collect() { var before = GC.GetTotalMemory(false); if (GarbageCollector.CollectIncremental(1000000)) { if (GarbageRemains) { var after = GC.GetTotalMemory(false); Log.Warning($"collection complete - { (before - after)} Collected - {after.ToMb():0.00}MB in heap", true); } GarbageRemains = false; // Log.Warning("collection complete", true); } else { GarbageRemains = true; // Log.Warning("garbage remains", true); } }