Skip to content

Instantly share code, notes, and snippets.

@chebizarro
Last active October 12, 2015 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chebizarro/f35a6afc4b1c3b43394b to your computer and use it in GitHub Desktop.
Save chebizarro/f35a6afc4b1c3b43394b to your computer and use it in GitHub Desktop.
A simple test to show the memory leak from the Vala Compiler called via libvala
public static void parse (string[] args) {
Vala.Parser parser = new Vala.Parser ();
Vala.CodeContext context = new Vala.CodeContext();
parser.parse (context);
Vala.CodeContext.push(context);
foreach (var path in args)
if (path.has_suffix (".vala") || path.has_suffix (".vapi") || path.has_suffix (".gs"))
context.add_source_file (new Vala.SourceFile (context, Vala.SourceFileType.SOURCE, path));
context.add_external_package("glib-2.0");
context.add_external_package("gobject-2.0");
context.add_external_package("libvala-0.30");
foreach (var src in context.get_source_files ())
parser.visit_source_file (src);
context.check ();
Vala.CodeContext.pop();
}
/* the arguments are an array of full paths to valid Vala files */
public static int main (string[] args) {
int i = 0;
while (i < 20) {
// simulate calling the compiler multiple times
parse(args);
i++;
}
return 0;
}
@chebizarro
Copy link
Author

to compile - valac libvalaleak.vala --pkg libvala-0.XX to run simply pass the full path of any number of vala files

@chebizarro
Copy link
Author

Interesting results...
vala_code_visitor_ref//unref 80/100
vala_code_context_ref/unref 31920/31880

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment