Applications can have memory leaks – Don't let it happen
When your building an application its not that uncommon to create small memory leaks when working on the client end or mobile for that mater most of the time these issues are not very major but the bigger the application is or the weaker the mobile device is the more battery you will drain from the user and worse.So it's time we test out our application and figure out where do we need to improve it to avoid memory leaks.
Video Transcript
00:00Alright, so as we said in the last video, it's all about testing and making sure that
00:04it's in good running order before you publish it to a real live application.
00:09Even try to run the application on your mobile device locally for a few weeks, get other
00:13people to use it if you could.
00:15Now with that said, one of the stuff that I noticed as soon as I actually tried it
00:19on my device was that the copy was too small.
00:21That's easy enough.
00:22I'm just going to go into the text format and doubled up the size to make it more
00:26beautifully visible.
00:27The next thing that wasn't really visible because it actually looks like it works
00:30perfectly is the fact that every time we run the application, we're adding more text
00:34fields in.
00:35In other words, every time we rotate the application, we're adding more memory onto
00:39the application.
00:40If you actually sit and do that for a few hours or maybe a few weeks, you might actually
00:44crash the application because it's getting more and more and more information in it.
00:49What you want to do is you want to make sure that you're getting rid of the text
00:52fields each time before you add them in.
00:55To do that, what I'm going to do is I'm just going to go into my refresh ruler line.
00:58They're right in the beginning there.
00:59I'm just going to add a very simple logic.
01:02As our ruler bucket, our movie clip, our sprite that is called the ruler, doesn't
01:07have anything in it but our numbers, it should be very easy for us to remove them.
01:12What we're going to do is we're going to make a while loop.
01:15We're going to ask is while our ruler.numChildren is greater than one,
01:19basically.
01:20As long as it's not zero, what do we want to do?
01:22We want to do only one thing.
01:24We want to go to the ruler and remove the child at position zero.
01:30Basically, in this way, in these two lines, we're making sure that we're
01:33removing everything out of the ruler before we continue on.
01:37Just as much as we made sure that we deleted whatever was there before each
01:40time from the actual graphics that we drew, so we started off with clearing
01:45the graphics.
01:46Here, we're starting off by making sure that there's nothing there.
01:49If there isn't anything, the value that will come back is zero, so we won't
01:52remove anything.
01:53If there's 10 elements or more, it's just going to go through that loop
01:56removing one by one until it's 9, 8, 7, 6, until it gets to zero.
02:00Until it gets to zero, it will continue removing all the elements each
02:02time we refresh the ruler.
02:05Literally now that we do that, if we run our application one last time
02:08before we wrap up the actual programming part, that was weird.
02:16Got a recording on a recording.
02:18That wasn't intended.
02:19Oh, that's kind of nice, I'll be able to see myself.
02:23If I'm going to go into my settings, enable the auto-orientation just
02:26to test it out and see that it looks nicely, ultimately reshuffle it
02:30and everything looks nice, no matter how or what direction we're in.
02:34Awesome.
02:35That's exactly what we wanted it to do, and we're really, really happy
02:38with our application.
02:39All that's left to do in this application is to wrap it up and get it
02:42ready to be on the store, so let's do that in the following next videos.
