It is currently April 19th, 2024, 4:08 pm

C# plugins aren't unloaded properly

Report bugs with the Rainmeter application and suggest features.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

C# plugins aren't unloaded properly

Post by death.crafter »

This isn't the first time I have noticed it but something about this behaviour is concerning.

Now, if we load a skin with a C# plugin and then unload it, you can't delete the plugin from the Plugins folder, citing an error it is still being used by Rainmeter.

Also if a C# plugin is unloaded the memory it uses isn't released. For example if you load PowershellRM plugin by khanhas then memory usage would increase by 15mb or so, but when you unload the skin using it the memory usage stays the same.

I don't know much about PowershellRM but if you make an example plugin say:

Code: Select all

using System;
using System.Runtime.InteropServices;
using Rainmeter;

namespace PluginEmpty
{
    class Measure
    {
        static public implicit operator Measure(IntPtr data)
        {
            return (Measure)GCHandle.FromIntPtr(data).Target;
        }
        public IntPtr buffer = IntPtr.Zero;
    }

    public class Plugin
    {
        [DllExport]
        public static void Initialize(ref IntPtr data, IntPtr rm)
        {
            data = GCHandle.ToIntPtr(GCHandle.Alloc(new Measure()));
            Rainmeter.API api = (Rainmeter.API)rm;
        }

        [DllExport]
        public static void Finalize(IntPtr data)
        {
            Measure measure = (Measure)data;
            if (measure.buffer != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(measure.buffer);
            }
            GCHandle.FromIntPtr(data).Free();
        }

        [DllExport]
        public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
        {
            Measure measure = (Measure)data;
        }

        [DllExport]
        public static double Update(IntPtr data)
        {
            Measure measure = (Measure)data;

            return 0.0;
        }
    }
}
you can notice the delete thing. Memory won't be affected noticeably.

Here is an example skin to test this. Clicking on it will take you to plugins folder:
CSExample_.rmskin
You do not have the required permissions to view the files attached to this post.
from the Realm of Death