c# - What could cause this memory issue? -
i'm working on app windows phone 8, , i'm having memory leak problem. first background. app works (unfortunately) using webbrowsers pages. pages pretty complex lot of javascript involved.
the native part of app, written in c#, responsible doing simple communication javascript(e.g. native delegate javascript communicate server), make animation page transition, tracking, persistance, etc. done in unique phoneapplicationpage.
after had crashes out of memory exceptions, started profiling app. can see webbrowsers, big part of the app, being disposed correctly. problem i'm seeing memory continues increase. what's worse, have little feedback profiler. understand, profiler graph says there big problem, while profiler numbers there's no problem @ all...
note: step represents navigation webbrowser webbrowser. spike created (i suppose) animation between 2 controls. in span i've selected in image, doing navigation forward , 1 backward having maxium of 5 webbrowsers (2 menus there, 1 index page, 1 page navigate , 1 page navigate to). @ every navigation profiler shows correct number of webbrowsers: 5 after navigating forward, 4 after navigating backward.
note 2: have added red line make clearer memory going in span of time
as can see image memory usage pretty big numbers it's low , in span of time, retained allocation lower when started...
i hope i've included enough information. want ideas on cause problem. ideas far are:
-the javascript in webbrowser doing wrong (e.g. not cleaning event handler). if case, shouldn't webbrowser release memory when destroyed?
-using unique phoneapplicationpage evil not supposed done, , changing structure may cause this.
-other?
another question: why graph show correct amount of memory use while number doesn't?
if need more info profiler, ask , post them tomorrow.
i don't think there enough information find cause leak, , without posting entire solution not sure there can be, since question locating root cause of it...
can offer approach have used when had own memory leak.
the technique to:
- open memory profiler. screenshot see using one. used perfmon. this article has material setting perfmon , @fmunkert explains rather well.
- locate area in code suspect leak in area. part depending on having guesses part of code responsible issue.
- push leak extreme: use labels , "goto" isolating area / function , repeat suspicious code many times (a loop work to. find goto more convenient matter).
- in loop have used breakpoint halted every 50 hits examining delta in memory usage. of course can change value feet noticeable leak change in application.
- if have located area causes leak, memory usage should rapidly spike. if memory usage not spike, repeat stages 1-4 area of code suspect being root cause. if does, continue 6.
- in area have found cause, use same technique (goto + labels) zoom in , isolate smaller parts of area until find source of leak (please don't downvote me recursive step... :0) ).
please note down sides of method are:
- if allocating object in loop, it's disposal should contained in loop.
- if have more 1 source of leak, makes harder spot (yet still possible)
please leave comment if further explanations required.
luck...
Comments
Post a Comment