protected override void Dispose(bool isDisposing)
        {
            if (!alreadyDisposed)
            {
                alreadyDisposed = true;

                if (isDisposing)
                {
                    // release managed resources
                }

                lock (LockObject)
                {
                    if (IsSafeToDisposeNativeBassLibrary())
                    {
                        // 0 - free all loaded plugins
                        if (!bassServiceProxy.PluginFree(0))
                        {
                            Trace.WriteLine("Could not unload plugins for Bass library.", "Error");
                        }

                        if (!bassServiceProxy.BassFree())
                        {
                            Trace.WriteLine("Could not free Bass library. Possible memory leak!", "Error");
                        }
                    }

                    initializedInstances--;
                }
            }
        }
            public void Dispose()
            {
                GC.SuppressFinalize(this);

                if (!alreadyDisposed)
                {
                    if (Interlocked.Decrement(ref initializedInstances) == 0)
                    {
                        // 0 - free all loaded plugins
                        if (!proxy.PluginFree(0))
                        {
                            Trace.WriteLine("Could not unload plugins for Bass library.", "Error");
                        }

                        if (!proxy.BassFree())
                        {
                            Trace.WriteLine("Could not free Bass library. Possible memory leak!", "Error");
                        }
                    }
                }

                alreadyDisposed = true;
            }