コード例 #1
0
ファイル: VMHeap.cs プロジェクト: GlaireDaggers/cozi-lang
        public void Collect(List <uint> roots)
        {
            // first, unset every allocation's Mark flag if it isn't pinned, otherwise treat as root and scan if pinned
            foreach (var alloc in _heap)
            {
                alloc.Mark = alloc.Pin;

                if (alloc.Pin)
                {
                    Scan(alloc.Handle);
                }
            }

            // next, scan each of the given roots
            foreach (var ptr in roots)
            {
                Scan(ptr);
            }

            // at this point, any allocation we failed to mark is unused and may be collected
            foreach (var alloc in _heap)
            {
                if (!alloc.Mark)
                {
                    _usedMem -= alloc.Memory.Memory.Length;

                    _allocator.Free(alloc.Memory);

                    alloc.Memory = new MemorySpan(null);
                    alloc.Type   = null;
                }
            }
        }
コード例 #2
0
        public void Release()
        {
            if (--_useCount == 0)
            {
                _memoryAllocator.Free(this);
            }

            Debug.Assert(_useCount >= 0);
        }