Graphviz Issue Tracker
Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0002214graphvizGraph Librariespublic2012-03-26 04:122014-01-22 20:02
Reporterjohannes 
Assigned Toerg 
PriorityhighSeveritymajorReproducibilityalways
StatusassignedResolutionreopened 
PlatformiPadOSiOSOS Version5.1
Summary0002214: Memory Leak through gvContextPlugins
DescriptionThere is a memory leak after calling gvContextPlugins when using Graphviz as a library on an iOS device. The leak is always reproducible (and is also in the Graphviz application for OS X). The amount of the leaked memory increases with the graph size.
Steps To Reproduce1. Building the library
2. Using the Code below to load the symbols and use the library in the Objective-C program

/**************************************************************************************************
 * builtins.c
 * Defines the list of preloaded symbols, is supposed to be compiled and linked with the project
 */
#include "gvplugin.h"

extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
extern gvplugin_library_t gvplugin_neato_layout_LTX_library;
extern gvplugin_library_t gvplugin_core_LTX_library;
extern gvplugin_library_t gvplugin_quartz_LTX_library;
extern gvplugin_library_t gvplugin_visio_LTX_library;

lt_symlist_t lt_preloaded_symbols[] =
{
    { "gvplugin_dot_layout_LTX_library", &gvplugin_dot_layout_LTX_library},
    { "gvplugin_neato_layout_LTX_library", &gvplugin_neato_layout_LTX_library},
    { "gvplugin_core_LTX_library", &gvplugin_core_LTX_library},
    { "gvplugin_quartz_LTX_library", &gvplugin_quartz_LTX_library},
    { "gvplugin_visio_LTX_library", &gvplugin_visio_LTX_library},
    { 0, 0}
};



/**************************************************************************************************
 * AppDelegate.m
 * Reduced example with just the the needed method
 */
#import "AppDelegate.h"
#import "gvc.h"

@implementation AppDelegate

@synthesize window = _window;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    // Graphviz Example
    Agraph_t *g;
    GVC_t *gvc;
    // load the plugins from builtins.c; here the leak originates
    gvc = gvContextPlugins(lt_preloaded_symbols, 0);
        
    g = agopen("G", AGFLAG_DIRECTED);
        
    // create three example nodes (two boxes, one hexagon)
    Agnode_t *node1 = agnode(g, "Box 1");
    agsafeset(node1, "shape", "box", "");
        
    Agnode_t *node2 = agnode(g, "Hexagon 1");
    agsafeset(node2, "shape", "hexagon", "");
        
    Agnode_t *node3 = agnode(g, "Box 2");
    agsafeset(node3, "shape", "box", "");
        
    // connect the nodes
    agedge(g, node1, node2);
    agedge(g, node2, node3);
        
    // layout graph
    gvLayout(gvc, g, "dot");
        
    // print layout
#if TARGET_IPHONE_SIMULATOR
        NSLog(@"Can not write to stdout in simulator");
#else
        agwrite(g, stdout);
#endif

    // free memory
    gvFreeLayout(gvc, g);
    agclose(g);

    return YES;
}

@end
TagsNo tags attached.
AUXILLARY-FILES
DATE-FIXED
FIX-COMMENT
FORMER-ID
INPUT-FILE
OUTPUT-FILE
STATUS-COMMENT
VERSION2.28
Attached Files

- Relationships

-  Notes
User avatar (0000213)
erg (administrator)
2012-03-26 15:57

Normally, an application will allocate a single GVC_t and use it as long as the process is alive. If you want to create a new one every time you do a layout, you should call gvFreeContext(gvc) before leaving the application function. This should free the resources stored in gvc. If you still see leaking after doing this, please let us know.
User avatar (0000214)
johannes (reporter)
2012-03-27 02:12

Thanks for the advice. I just added the gvFreeContext-call after I closed the graph. If my understanding is correct then this is the appropriate way, since the graph is used in the context and should be closed before the context is freed. Unfortunately it helped only a bit and reduced the leaking just by a fraction.
I don't know if this helps you, but I added the call tree for the leaking provided by Apples Instruments.
- application didFinishLaunchingWithOptions:
  - gvContextPlugins
    - gvconfig
      - gvconfig_plugin_install_builtins
        - gvconfig_plugin_install_from_library
          - gvplugin_install
            - gmalloc
User avatar (0000244)
johannes (reporter)
2012-05-07 02:25

Hello. I just wanted to know if there is any development regarding the memory leak? Is there something else I have to do to eliminate the leaks? Or is there a new fixed version to be expected in the near future?

Thank you very much in advance.
User avatar (0000258)
erg (administrator)
2012-05-11 09:40

It is definitely high on my list of priorities.
User avatar (0000670)
Mike M (reporter)
2014-01-22 20:02

Any news? I can still reproduce it with 2.34.

- Issue History
Date Modified Username Field Change
2012-03-26 04:12 johannes New Issue
2012-03-26 15:57 erg Note Added: 0000213
2012-03-26 15:57 erg Assigned To => erg
2012-03-26 15:57 erg Status new => closed
2012-03-26 15:57 erg Resolution open => no change required
2012-03-27 02:12 johannes Note Added: 0000214
2012-03-27 02:12 johannes Status closed => feedback
2012-03-27 02:12 johannes Resolution no change required => reopened
2012-05-07 02:25 johannes Note Added: 0000244
2012-05-07 02:25 johannes Status feedback => assigned
2012-05-11 09:40 erg Note Added: 0000258
2014-01-22 20:02 Mike M Note Added: 0000670
2014-01-24 13:25 erg Note View State: 0000258: private
2014-01-24 13:25 erg Note View State: 0000258: public


MantisBT 1.2.5[^]
Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker