After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 622440 - destructors for structs
destructors for structs
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Structs
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-06-22 20:56 UTC by celil.kj
Modified: 2018-05-22 13:39 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description celil.kj 2010-06-22 20:56:56 UTC
Is there a fundamental reason why structs can have constructors but not destructors? I knows structs are stack based, but a destructor may still be necessary if we manually allocate memory in them.

For example when I try to compile the following test

struct Test
{
    int* pointer;

    Test()
    {
        pointer = new int[10];   
    }

    ~Test()
    {
        stdout.printf("Destroying!\n");
        delete pointer;
    }
}

void main()
{
    var p = Test();
}

I get an error message:

error: unexpected declaration in struct
    ~Test()
    ^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
Comment 1 geert jordaens 2011-08-03 18:21:35 UTC
True that this causes a memory leak.

If pointer is defined like below the destructor is correctly declared.

struct Test
{
    int[] pointer;

    Test()
    {
        pointer = new int[10];
    }

}

void main()
{
    var p = Test();
}
Comment 2 GNOME Infrastructure Team 2018-05-22 13:39:23 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/111.