Can you spot where I'm leaking?

I appear to be leaking moving between two menu scenes:

main menu

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
module(..., package.seeall)
 
 
function new()
        collectgarbage('collect')
        print( "main, MemUsage: " .. collectgarbage("count") )
 
        local local_group = display.newGroup()
        
        ----------------------------------------------------------------------------------------        
        function ChangeScene(e)
                if e.target.GameMode then
                        _G.GAME_MODE = e.target.GameMode
                end
                
                CleanupButtonListeners()
                director:changeScene(e.target.Scene)
        end
        
        ----------------------------------------------------------------------------------------        
        function OpenFeintDashboard()
                _G.openfeint.launchDashboard()
        end
 
        ----------------------------------------------------------------------------------------        
        function SendEmail()
                system.openURL("")
        end
 
        ----------------------------------------------------------------------------------------        
        function ViewWebsite()
                system.openURL("")
        end
        
        ----------------------------------------------------------------------------------------        
        -- buttons
        local title_screen
        local score_attack
        local time_attack
        local endless
        local scores
        local options
        local help
        local mail
        local web
                
        ----------------------------------------------------------------------------------------        
        function init()
        
                local buttonfactory = require "buttonfactory"
        
                title_screen = display.newImageRect('titlescreen.png', 320, 480)
                title_screen:setReferencePoint(display.TopLeftReferencePoint)
                title_screen.x = 0
                title_screen.y = 0
                local_group:insert(title_screen)
        
                local x_pos = 15
        
                score_attack = buttonfactory.GetNewButton('Score Attack', "button", "button_over", ChangeScene)
                score_attack:setReferencePoint(display.TopLeftReferencePoint)
                score_attack.x = x_pos
                score_attack.y = 137.5
                score_attack.Scene = 'scoreattackmenu'
                score_attack.GameMode = 'SCORE_ATTACK'
                
                local_group:insert(score_attack)
        
                time_attack = buttonfactory.GetNewButton('Time Attack', "button", "button_over", ChangeScene)
                time_attack:setReferencePoint(display.TopLeftReferencePoint)
                time_attack.x = x_pos
                time_attack.y = 185.
                time_attack.Scene = 'timeattackmenu'
                time_attack.GameMode = 'TIME_ATTACK'
        
                local_group:insert(time_attack) 
        
                endless = buttonfactory.GetNewButton('Endless', "button", "button_over", ChangeScene)
                endless:setReferencePoint(display.TopLeftReferencePoint)
                endless.x = x_pos
                endless.y = 234.
                endless.Scene = 'gamemain'
                endless.GameMode = 'ENDLESS'
        
                local_group:insert(endless)
                
                scores = buttonfactory.GetNewButton('', "button_of", "button_of_over", OpenFeintDashboard)
                scores:setReferencePoint(display.TopLeftReferencePoint)
                scores.x = x_pos
                scores.y = 283.
        
                local_group:insert(scores)
                
                options = buttonfactory.GetNewButton('Options', "button", "button_over", ChangeScene)
                options:setReferencePoint(display.TopLeftReferencePoint)
                options.x = x_pos
                options.y = 332.
                options.Scene = 'options'
        
                local_group:insert(options)
        
                help = buttonfactory.GetNewButton('', "help", "help_over", ChangeScene)
                help:setReferencePoint(display.CenterReferencePoint)
                help.x = centerX - 53
                help.y = 415
                help.Scene = 'options'
        
                local_group:insert(help)
                                
                mail = buttonfactory.GetNewButton('', "mail", "mail_over", SendEmail)
                mail:setReferencePoint(display.CenterReferencePoint)
                mail.x = centerX
                mail.y = 415
        
                local_group:insert(mail)
                
                web = buttonfactory.GetNewButton('', "web", "web_over", ViewWebsite)
                web:setReferencePoint(display.CenterReferencePoint)
                web.x = centerX + 53
                web.y = 415
        
                local_group:insert(web)
                
                local copyright_text = display.newText("Blah Blah Blah", 13)
                copyright_text:setTextColor(255, 255, 255)
                
                local_group:insert(copyright_text)
                
                local rights_text = display.newText("All rights reservered", centerX, 465, 'Varela', 13)
                rights_text:setTextColor(255, 255, 255)
                
                local_group:insert(rights_text)         
        end
        
        ----------------------------------------------------------------------------------------        
        function CleanupButtonListeners()
                title_screen:removeEventListener("touch",       title_screen)
                score_attack:removeEventListener("touch",       score_attack)
                time_attack:removeEventListener("touch",        time_attack)
                endless:removeEventListener("touch",            endless)
                scores:removeEventListener("touch",             scores)
                options:removeEventListener("touch",            options)
                help:removeEventListener("touch",                       help)
                mail:removeEventListener("touch",                       mail)
                web:removeEventListener("touch",                        web)
        end
 
        init()
 
        return local_group
end

This is with director 1.2 btw.

Add

local_group:removeSelf() below the director change scene call in both your ChangeScene functions

Part of what I did to clean up the memory leaks in my app (using Director 1.2) was to use Jonathan Beebe's cleangroup replacement.

http://jonbeebe.tumblr.com/post/3760389212/proper-group-cleaning-in-corona-script-download

views:1434 update:2011/10/12 18:33:00
corona forums © 2003-2011