Shinobi Charts - Memory Leak


Howdy Folks!

I am having a problem where I create a shinobi chart, destroy it, then re-create it and Shinobi Charts is not releasinging the memory. Any help anyone could give me would be greatly appreciated.

To replicate the error that I’m having I modified the ‘Bar Chart’ example with the following code and ran in a profiler for ‘allocations’


@interface ViewController ()


@implementation ViewController

- (void)viewDidLoad
    [super viewDidLoad];
	[self createChart];
    self.view.backgroundColor = barChart.backgroundColor;

		for(UIView *v in barChart.subviews)
			[v removeFromSuperview];
		barChart = nil;
		dataSource = nil;
		topTenCountriesAreaData = nil;
	[self createChart];

    //Create a chart object capable of displaying countries by area using bars
	CGRect tRect = CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height - 100);
    barChart = [ShinobiChart barChartForCountryByAreaWithFrame:tRect];
    //Enter your trial license key here
    //barChart.licenseKey = @"";
    barChart.title = @"Top Ten Countries by Area";
    //Create our top ten data and assign it to our datasource
    topTenCountriesAreaData = [TopTenCountriesAreaData new];
    dataSource = [Datasource new];
    dataSource.countriesAreaData = topTenCountriesAreaData;
    barChart.datasource = dataSource;
    //set this controller to be the delegate for our chart
    barChart.delegate = self;
    [self.view addSubview:barChart];

- (void)viewDidUnload
    [super viewDidUnload];
    // Release any retained subviews of the main view.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    return YES;

- (void)sChartRenderFinished:(ShinobiChart *)chart {
    BOOL iPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
    //use multi-line title on the yAxis for iPad
    if (iPad) {
        chart.yAxis.titleLabel.numberOfLines = 0;
        [chart.yAxis.titleLabel sizeToFit];

Thank you guys sooooooo much! :slight_smile: :slight_smile:




Hi Matthew,

As you discovered :wink: the answer is to

[Barchart removefromsuperview];


Robin Sillem

Lead Developer