コード例 #1
0
        /// <summary>
        /// Called to destroy the C++ instance. This method can be called more than
        /// once: only the first call will do some actual work.
        /// </summary>
        /// <remarks>
        /// If the virtual jump table has been replaced the original data will be
        /// restores using <see cref="VirtualJumpTable"/>. Then the <see cref="m_Destruct"/>
        /// <see cref="Delegate"/> is called on the <see cref="ClassPointer"/>. Finally
        /// all data removed from the garbage collection is reattached to it. This
        /// includes all <see cref="Delegate"/> <see cref="m_Delegates"/> from
        /// calls to <see cref="this"/> and the fields <see cref="m_Table"/> and
        /// <see cref="m_Class"/>.
        /// </remarks>
        public void Dispose()
        {
            // Restore table
            if (IntPtr.Zero != m_OrgTable)
            {
                // Process
                VirtualJumpTable = m_OrgTable;

                // Once
                m_OrgTable = IntPtr.Zero;
            }

            // Cleanup
            if (null != m_Destruct)
            {
                // Process
                m_Destruct(ClassPointer);

                // Done
                m_Destruct = null;
            }

            // Release delegates
            foreach (GCHandle hDel in m_Delegates)
            {
                hDel.Free();
            }

            // Release handles
            if (m_Table.IsAllocated)
            {
                m_Table.Free();
            }
            if (m_Class.IsAllocated)
            {
                m_Class.Free();
            }

            // Detach
            m_Delegates.Clear();
            m_TableMem = null;
            m_ClassMem = null;

            // No need to finalize
            GC.SuppressFinalize(this);
        }
コード例 #2
0
        /// <summary>
        /// Called to destroy the C++ instance. This method can be called more than
        /// once: only the first call will do some actual work.
        /// </summary>
        /// <remarks>
        /// If the virtual jump table has been replaced the original data will be
        /// restores using <see cref="VirtualJumpTable"/>. Then the <see cref="m_Destruct"/>
        /// <see cref="Delegate"/> is called on the <see cref="ClassPointer"/>. Finally
        /// all data removed from the garbage collection is reattached to it. This
        /// includes all <see cref="Delegate"/> <see cref="m_Delegates"/> from
        /// calls to <see cref="this"/> and the fields <see cref="m_Table"/> and
        /// <see cref="m_Class"/>.
        /// </remarks>
        public void Dispose()
        {
            // Restore table
            if (IntPtr.Zero != m_OrgTable)
            {
                // Process
                VirtualJumpTable = m_OrgTable;

                // Once
                m_OrgTable = IntPtr.Zero;
            }

            // Cleanup
            if (null != m_Destruct)
            {
                // Process
                m_Destruct( ClassPointer );

                // Done
                m_Destruct = null;
            }

            // Release delegates
            foreach (GCHandle hDel in m_Delegates) hDel.Free();

            // Release handles
            if (m_Table.IsAllocated) m_Table.Free();
            if (m_Class.IsAllocated) m_Class.Free();

            // Detach
            m_Delegates.Clear();
            m_TableMem = null;
            m_ClassMem = null;

            // No need to finalize
            GC.SuppressFinalize( this );
        }