[Vala] Class finalizer

6 views
Skip to first unread message

Derek Dai

unread,
Mar 8, 2012, 1:03:29 AM3/8/12
to vala...@gnome.org
Hi,

In Vala, if I allocate resource in static construct block, where can I free
it? Thanks.

Derek Dai

Luca Bruno

unread,
Mar 8, 2012, 6:30:04 AM3/8/12
to Derek Dai, vala...@gnome.org

static ~Foo () { }

--
www.debian.org - The Universal Operating System

Jacques-Pascal Deplaix

unread,
Mar 8, 2012, 4:46:05 PM3/8/12
to Luca Bruno, vala-list
On 03/08/2012 12:30 PM, Luca Bruno wrote:
> On Thu, Mar 8, 2012 at 7:03 AM, Derek Dai <daid...@gmail.com> wrote:
>
>> Hi,
>>
>> In Vala, if I allocate resource in static construct block, where can I free
>> it? Thanks.
>>
> static ~Foo () { }
>
Hi,

I'm very interested about that. But when I tried that solution, valac
wrote an error:
error: static destructors are only supported for dynamic types

What is 'dynamic types' ?
And how I'm supposed to use this code ?

Thanks.
_______________________________________________
vala-list mailing list
vala...@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list

Luca Bruno

unread,
Mar 8, 2012, 5:14:21 PM3/8/12
to Jacques-Pascal Deplaix, vala-list
Static/class destructors are pointless in applications, as the memory will
be freed on exit. Dynamic types are those loaded and unloaded with plugins,
it works with [ModuleInit]. That's where it makes sense.

Derek Dai

unread,
Mar 9, 2012, 1:09:37 AM3/9/12
to vala...@gnome.org
I tried the syntax too. The same issue.

But it's OK with class construct/destruct.
class MyClass : Object
{
static string message = null;

class construct
{
message = "Bla";
}

class ~MyClass()
{
message = null;
}
}

Derek Dai


On Fri, Mar 9, 2012 at 5:39 AM, <vala-lis...@gnome.org> wrote:

> Send vala-list mailing list submissions to
> vala...@gnome.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.gnome.org/mailman/listinfo/vala-list
> or, via email, send a message with subject or body 'help' to
> vala-lis...@gnome.org
>
> You can reach the person managing the list at
> vala-li...@gnome.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of vala-list digest..."
>
>
> Today's Topics:
>
> 1. Is there a Linux distribution in which vtg (vala tools for
> gedit) works out-of the box ? (Serge Hulne)
> 2. calling the parent constructor. (Rodrigo Herefeld)
> 3. Re: calling the parent constructor. (Andrew Higginson)
> 4. vala + policykit (D.H. Bahr)
> 5. Re: calling the parent constructor. (Luca Bruno)
> 6. Re: DBus server-side codegen (Jens Georg)
> 7. Re: DBus server-side codegen (Eric Gregory)
> 8. Re: Class finalizer (Jacques-Pascal Deplaix)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 8 Mar 2012 14:15:57 +0100
> From: Serge Hulne <serge...@gmail.com>
> To: vala-list <vala...@gnome.org>
> Subject: [Vala] Is there a Linux distribution in which vtg (vala tools
> for gedit) works out-of the box ?
> Message-ID:
> <CA+eGGBD6+zf-jJBaFc+iZDXvrm=21ntEqt01Sc...@mail.gmail.com
> >
> Content-Type: text/plain; charset="iso-8859-1"
>
> Is there a Linux distribution in which vtg (vala tools for gedit) works
> out-of the box ?
>
> In other words, is there a version of Linux which provides Vala, vtg as
> ready-to install packages ?
>
> I am asking this question because, if on one hand quite easy to install
> Vala from source under Linux, on the other hand it often seems problematic
> to get a matching set of versions of Gnome, Gedit, Gedit plugins (aimed at
> Vala development, such as Valencia, vtg, etc ...) in order to build a
> coherent Vala envelopment environment.
>
>
> Alternatively: Does anybody know which Linux disto is used by the
> developer(s) of VTG ?
>
>
> Thanks,
> Serge.
>
> ------------------------------
>
> Message: 2
> Date: Thu, 8 Mar 2012 10:55:28 -0300
> From: Rodrigo Herefeld <rodrigo....@gmail.com>
> To: Vala List <vala...@gnome.org>
> Subject: [Vala] calling the parent constructor.
> Message-ID:
> <CAHz3HDDYu7t_GmZb4uNEuOO-...@mail.gmail.com
> >
> Content-Type: text/plain; charset="utf-8"
>
> Hi all!
> i wrote a class extending a Gtk.Dialog, on my constructor i use
> "this.vbox" to put the widgets, until this comom,
> but when i compile i've got a warning "assignment from incompatible pointer
> type", i wonder this is because the
> Dialog is no initialized at this point, even the program working i's like
> to go away with the message, in python i
> must call the parent init before can go on like this:
>
> Dialog.__init__(self)
>
> how do i make this in vala?
>
> --
> Rodrigo Cesar Herefeld
>
> ------------------------------
>
> Message: 3
> Date: Thu, 08 Mar 2012 15:57:12 +0000
> From: Andrew Higginson <at.hig...@gmail.com>
> To: vala...@gnome.org
> Subject: Re: [Vala] calling the parent constructor.
> Message-ID: <4F58D6D8...@gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi Rodrigo
>
> > Hi all!
> > i wrote a class extending a Gtk.Dialog, on my constructor i use
> > "this.vbox" to put the widgets, until this comom,
> > but when i compile i've got a warning "assignment from incompatible
> pointer
> > type", i wonder this is because the
> > Dialog is no initialized at this point, even the program working i's like
> > to go away with the message, in python i
> > must call the parent init before can go on like this:
> >
> > Dialog.__init__(self)
> >
> > how do i make this in vala?
>
> In Vala you don't need to do this (and cannot), it is done for you when
> you compile.
>
> I would not worry too much about warnings, however if it is causing a
> problem,please reply to this with the code you use, and the problem that
> you have.
>
> HTH
>
> --
> Andrew Higginson
>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 08 Mar 2012 11:04:01 -0500
> From: "D.H. Bahr" <db...@uci.cu>
> To: vala...@gnome.org
> Subject: [Vala] vala + policykit
> Message-ID: <1331222641.1871.21.camel@compaq>
> Content-Type: text/plain; charset="UTF-8"
>
> Hey there!!
>
> Can anyone give a tip on how to use policykit in vala?
> --
>
> Sw.E. D.H. Bahr
> Nova Desktop Development Leader
> CESOL (Free/Libre Software Centre)
> UCI (University of Informatics Sciences)
> Havana, Cuba
>
>
>
>
>
>
> Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE
> ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
> http://www.antiterroristas.cu
> http://justiciaparaloscinco.wordpress.com
>
>
> ------------------------------
>
> Message: 5
> Date: Thu, 8 Mar 2012 17:19:46 +0100
> From: Luca Bruno <letha...@gmail.com>
> To: Andrew Higginson <at.hig...@gmail.com>
> Cc: vala...@gnome.org
> Subject: Re: [Vala] calling the parent constructor.
> Message-ID:
> <CAHXTfc9pYx8MRPxjtTKtF1Om...@mail.gmail.com
> >
> Content-Type: text/plain; charset="utf-8"
>
> On Thu, Mar 8, 2012 at 4:57 PM, Andrew Higginson <at.hig...@gmail.com
> >wrote:
>
> > In Vala you don't need to do this (and cannot), it is done for you when
> > you compile.
> >
>
> See
>
> https://live.gnome.org/Vala/FAQ#Why_can.27t_I_chain_up_to_base_constructor.3F


>
> --
> www.debian.org - The Universal Operating System
>

> ------------------------------
>
> Message: 6
> Date: Thu, 08 Mar 2012 18:37:04 +0200
> From: Jens Georg <ma...@jensge.org>
> To: Luca Bruno <letha...@gmail.com>
> Cc: vala...@gnome.org
> Subject: Re: [Vala] DBus server-side codegen
> Message-ID: <1331224624.2529.0.camel@laptop-jge>
> Content-Type: text/plain; charset="UTF-8"
>
> On Do, 2012-03-08 at 12:29 +0100, Luca Bruno wrote:
> > On Tue, Mar 6, 2012 at 9:48 PM, Eric Gregory <er...@yorba.org> wrote:
>
> > > Is there a codegen tool out there that can generate a Vala DBus adapter
> > > from the XML? Or is this something where I'd have to hand-roll (and
> > > hand-maintain) the adapter interface?
> > >
> >
> > Why do you need xml for the server?
> > http://live.gnome.org/Vala/DBusServerSample
>
> Well it makes sense when you want to implement server interface specs
> like e.g. MPRIS2 to save you from the dull task to write the interface
> in vala by hand.
>
>
>
>
> ------------------------------
>
> Message: 7
> Date: Thu, 8 Mar 2012 11:24:36 -0800
> From: Eric Gregory <er...@yorba.org>
> To: Luca Bruno <letha...@gmail.com>
> Cc: vala...@gnome.org
> Subject: Re: [Vala] DBus server-side codegen
> Message-ID:
> <CAKPMJnL6ghn4SuorKVsd5OPW...@mail.gmail.com
> >
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Thu, Mar 8, 2012 at 3:29 AM, Luca Bruno <letha...@gmail.com> wrote:
> >
> >
> > Why do you need xml for the server?
> > http://live.gnome.org/Vala/DBusServerSample
> >
>
> Ideally you want to code to the interface, not the other way around.
> That's why dbus-binding-tool and qdbusxml2cpp can generate the server-side
> code as well as the client-side code. I also worry that a Vala change
> could end up affecting the interface in some subtle way that could result
> in hard to track down bugs.
>
> But there's another hurdle here as well -- if I write the server without a
> formal interface, how do I generate the XML?
>
> - Eric
>
> ------------------------------
>
> Message: 8
> Date: Thu, 08 Mar 2012 22:46:05 +0100
> From: Jacques-Pascal Deplaix <jp.de...@gmail.com>
> To: Luca Bruno <letha...@gmail.com>
> Cc: vala-list <vala...@gnome.org>
> Subject: Re: [Vala] Class finalizer
> Message-ID: <4F59289D...@gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1


>
> On 03/08/2012 12:30 PM, Luca Bruno wrote:
> > On Thu, Mar 8, 2012 at 7:03 AM, Derek Dai <daid...@gmail.com> wrote:
> >
> >> Hi,
> >>
> >> In Vala, if I allocate resource in static construct block, where can I
> free
> >> it? Thanks.
> >>
> > static ~Foo () { }
> >
> Hi,
>
> I'm very interested about that. But when I tried that solution, valac
> wrote an error:
> error: static destructors are only supported for dynamic types
>
> What is 'dynamic types' ?
> And how I'm supposed to use this code ?
>
> Thanks.
>
>

> ------------------------------


>
> _______________________________________________
> vala-list mailing list
> vala...@gnome.org
> http://mail.gnome.org/mailman/listinfo/vala-list
>
>

> End of vala-list Digest, Vol 52, Issue 8
> ****************************************
>

Jacques-Pascal Deplaix

unread,
Mar 9, 2012, 5:24:25 PM3/9/12
to Derek Dai, vala-list
On 03/09/2012 07:09 AM, Derek Dai wrote:
> I tried the syntax too. The same issue.
>
> But it's OK with class construct/destruct.
> class MyClass : Object
> {
> static string message = null;
>
> class construct
> {
> message = "Bla";
> }
>
> class ~MyClass()
> {
> message = null;
> }
> }
>
> Derek Dai
It compile but the destructor is never called.
When is it supposed to be called ?

Luca Bruno

unread,
Mar 9, 2012, 6:08:18 PM3/9/12
to Jacques-Pascal Deplaix, vala-list, Derek Dai
On Fri, Mar 9, 2012 at 11:24 PM, Jacques-Pascal Deplaix <
jp.de...@gmail.com> wrote:

> It compile but the destructor is never called.
> When is it supposed to be called ?
>

I've sent an email some days ago in this thread about that.

Jacques-Pascal Deplaix

unread,
Mar 10, 2012, 4:21:22 PM3/10/12
to Luca Bruno, vala-list
On 03/10/2012 12:08 AM, Luca Bruno wrote:
> On Fri, Mar 9, 2012 at 11:24 PM, Jacques-Pascal Deplaix
> <jp.de...@gmail.com <mailto:jp.de...@gmail.com>> wrote:
>
> It compile but the destructor is never called.
> When is it supposed to be called ?
>
>
> I've sent an email some days ago in this thread about that.
>
I understood what you said but I was interested of the context of using
class destructors. I didn't know, I was intrigued. But I found it by my
self after sending this email.
Reply all
Reply to author
Forward
0 new messages