Skip to content

Commit aac4160

Browse files
Add dealloc methods to the demos.
This is proper Cocoa etiquette and may help others prevent crashes in their own apps.
1 parent 0bfc904 commit aac4160

6 files changed

+51
-3
lines changed

JBChartViewDemo/JBChartViewDemo/Controllers/Base/JBBaseTableViewController.m

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ - (void)loadView
2828
[self.view addSubview:self.tableView];
2929
}
3030

31+
- (void)dealloc
32+
{
33+
self.tableView.delegate = nil;
34+
self.tableView.dataSource = nil;
35+
}
36+
3137
#pragma mark - UITableViewDataSource
3238

3339
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

JBChartViewDemo/JBChartViewDemo/Controllers/JBAreaChartViewController.m

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
8484
return self;
8585
}
8686

87+
- (void)dealloc
88+
{
89+
_lineChartView.delegate = nil;
90+
_lineChartView.dataSource = nil;
91+
}
92+
8793
#pragma mark - Data
8894

8995
- (void)initFakeData

JBChartViewDemo/JBChartViewDemo/Controllers/JBBarChartViewController.m

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
7878
return self;
7979
}
8080

81+
- (void)dealloc
82+
{
83+
_barChartView.delegate = nil;
84+
_barChartView.dataSource = nil;
85+
}
86+
8187
#pragma mark - Date
8288

8389
- (void)initFakeData

JBChartViewDemo/JBChartViewDemo/Controllers/JBLineChartMissingPointsViewController.m

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
8686
return self;
8787
}
8888

89+
- (void)dealloc
90+
{
91+
_lineChartView.delegate = nil;
92+
_lineChartView.dataSource = nil;
93+
}
94+
8995
#pragma mark - Data
9096

9197
- (void)initFakeData

JBChartViewDemo/JBChartViewDemo/Controllers/JBLineChartViewController.m

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
8686
return self;
8787
}
8888

89+
- (void)dealloc
90+
{
91+
_lineChartView.delegate = nil;
92+
_lineChartView.dataSource = nil;
93+
}
94+
8995
#pragma mark - Data
9096

9197
- (void)initFakeData

README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ To initialize a <i>JBBarChartView</i>, you only need a few lines of code (see be
7272
barChartView.dataSource = self;
7373
barChartView.delegate = self;
7474
[self addSubview:barChartView];
75+
76+
Just like you would for a `UITableView`, ensure you clear these properties in your `dealloc`:
77+
78+
- (void)dealloc
79+
{
80+
JBBarChartView *barChartView = ...; // i.e. _barChartView
81+
barChartView.delegate = nil;
82+
barChartView.dataSource = nil;
83+
}
7584

7685
At a minimum, you need to inform the data source how many bars are in the chart:
7786

@@ -99,9 +108,18 @@ Lastly, ensure you have set the *frame* of your barChartView & call *reloadData*
99108
Similiarily, to initialize a JBLineChartView, you only need a few lines of code (see below). Line charts can also be initialized via a <b>nib</b> or with a <b>frame</b>.
100109

101110
JBLineChartView *lineChartView = [[JBLineChartView alloc] init];
102-
lineChartView.dataSource = self;
103-
lineChartView.delegate = self;
104-
[self addSubview:lineChartView];
111+
lineChartView.dataSource = self;
112+
lineChartView.delegate = self;
113+
[self addSubview:lineChartView];
114+
115+
Just like you would for a `UITableView`, ensure you clear these properties in your `dealloc`:
116+
117+
- (void)dealloc
118+
{
119+
JBLineChartView *lineChartView = ...; // i.e. _lineChartView
120+
lineChartView.delegate = nil;
121+
lineChartView.dataSource = nil;
122+
}
105123

106124
At a minimum, you need to inform the data source how many lines and vertical data points (for each line) are in the chart:
107125

0 commit comments

Comments
 (0)