Re: [Vala] Simple Memory Management Issue



I was able to work around it. Basically I never wanted the interface
to be called but the object implementing the interface. Only problem
is, its an unknown class at runtime. So I have no way of knowing how
to describe the object as a hash map.

var plugins = new Gee.HashMap<string, PlugPlug> ();

PlugPlug was the interface, not object. So when I loaded the object
after putting it into the hash map it would resolve to the interface's
run and not the object's run.

So instead I just used the registrars:
var plugins = new Gee.HashMap<string, PluginRegistrar> ();

Which changes the code to:
var has_plugin = plugins.has_key (choice);
if (!has_plugin) {
        var registrar = new PluginRegistrar<PlugPlug> (choice);
        var loaded = registrar.load ();
        if (loaded) {
                plugins[choice] = registrar;
                has_plugin = true;
        }
}
if (has_plugin) {
        var plugin = ((PluginRegistrar<PlugPlug>) plugins[choice]).new_object ();
        plugin.run (items);
}

In result it creates a new object every time but at least it works :\.


On Thu, Aug 18, 2011 at 5:21 AM, Luca Bruno <lethalman88 gmail com> wrote:
On Wed, Aug 17, 2011 at 07:48:36PM -0700, Joseph Montanez wrote:
Luca,

(gdb) bt
#0  0x0068fac5 in ?? ()
#1  0x0804b687 in plug_plug_run (self=0x8057700, items=0x8057cc8)
    at /home/joseph/Documents/ada/csv/plugplug-interface.c:41
#2  0x0804b399 in _vala_main () at /home/joseph/Documents/ada/csv/main.c:631
#3  0x0804b405 in main (argc=1, argv=0xbffff4f4) at
/home/joseph/Documents/ada/csv/main.c:648


Line 41 in the C code is:
void plug_plug_run (PlugPlug* self, GeeArrayList* items) {
      PLUG_PLUG_GET_INTERFACE (self)->run (self, items);
}

You probably have to implement the run() method.

--
http://www.debian.org - The Universal Operating System




-- 
Joseph Montanez
Web Developer
Gorilla3D
Design, Develop, Deploy



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]