-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathApplicationForm.cs
77 lines (62 loc) · 2.23 KB
/
ApplicationForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Ptvag.Dawn.Tools;
using System;
using System.Windows.Forms;
namespace MemoryDemo
{
public partial class ApplicationForm : Form
{
public ApplicationForm()
{
InitializeComponent();
}
// our child-form
private MapForm mapForm;
// This flag tests our memory leak detection by provoking memory-leak
private bool hasMemoryLeak;
private void openMapWindow1_Click(object sender, EventArgs e)
{
// set our "memory-leak flag" to false
hasMemoryLeak = true;
// open our map-window
ShowMapWindow();
}
private void openMapWindow2_Click(object sender, EventArgs e)
{
// set our "memory-leak flag" to false
hasMemoryLeak = false;
// open our map-window
ShowMapWindow();
}
private void ShowMapWindow()
{
// change button states
openMapWindow1.Enabled = false;
openMapWindow2.Enabled = false;
AddTruckButton.Enabled = true;
// create the modal dialog we want to test for leaks.
mapForm = new MapForm(this);
// show the modal dialog
mapForm.Show();
// attach to closed-event
mapForm.Closed += mapForm_Closed;
}
private void mapForm_Closed(object sender, EventArgs e)
{
// change button states
openMapWindow1.Enabled = true;
openMapWindow2.Enabled = true;
AddTruckButton.Enabled = false;
// disposing won't help here
mapForm.Dispose();
if (!hasMemoryLeak)
// this line fixes our memory leak inside the mapForm.
mapForm.FixMemoryLeak();
// At this point dlg should be the last reference to the modal dialog
// If the dialog causes a memory leak, a box will appear.
// It is possible that the box appears because the map control still
// loads tiles from xMap server. In this case the box should disappear after
// pressing retry.
DawnMemAssert<MapForm>.SetNullAndAssertDead(ref mapForm);
}
}
}