I have an application who fails silently (most of the time) and sometimes issue an Out Of Memory error.
That application downloads three images files for each day, the application stops on Labor day (09-04 or near).
The download is done in a loop.
I use securesocket (Xojo 2015r1), HTTPHeaders,
I also store report data in a Listbox, another in an html file [Desktop application]
I take the images URLs in an html page I download (and display in a TextArea).
The image is saved to disk using a Binary Stream.
I took some times to check if I set to Nil some object in the loop (Close and Nil sometimes). I read the whole loop contents without noticing anything that can be wrong, but as we all know, this does means much (we all can skip an offending line for whatever reason).
BTW: the reused variables are dimed in the loop.
I do not understand how this can happens.
But is your app trying to download 3 images every day (which I doubt) or does it try to download 3 images for every day but one year in advance? (which I think is the case)
In the latter case, it is something I have observed many times, even when using Threads, i.e. Picture objects are not really destroyed until the end of a method. It you are in a tight loop, pictures quickly fill up the whole memory.
I have tried MANY (and I mean MANY!!) things but the only workaround I could find is to do the following:
1. Make a global array of the paths to the Pictures to be loaded (you can even modify is while processing it)
2. Use a Thread to process a given number of Pictures (10, 20 or 50, it doesn’t really matter as long as you have enough memory)
3. When the Thread has finished, it sets up a Timer (with a period of zero) to restart itself, i.e. the Timer.Action contains something like “Thread.Run”
4. Repeat until the global array of paths is empty.
But is your app trying to download 3 images every day (which I doubt) or does it try to download 3 images for every day but one year in advance? (which I think is the case)[/quote]
Nothing from the future is available; I tak 3 files for each day from the past (eventually a whole year, or the last complete month to date when I am up-to -date).
Each downloaded file (the three a day files) are downloaded in the same Loop, if the loop condition to exit is not meet, I download a brand new set of 3 files.
Each set of 3 files have its own FolderItem and BinaryStream (that are destroyed and redim at each loop “re-entrance”)
I flush the BinaryStream before downloading the next image.
NO Picture object is used: I write the data to disk using a BinaryStream directly fro the HTTPSecureSocket.
With time, I added an option to display the downloaded image. But since this takes more time, I rarely use it (never in a year download process; Ive done that for some "1 month"downloadson this Monday and Tuesday (so I can watch/read them but I do not get any crash then. And since the process is really boring (thus this application), I have some more (2018-12) files to download.
One test I can do is to skip the images download part and watch what is saved in the html file (in a TextEditor / Loaded in Firefox); but I cannot download the files since their names will be contentsiiii.Ext (iii is a number and Ext is .gif or .jpg): unusable.
Another important information left in my brain is the intensive use of String to get the images URL, images files names, InternetHeaders (displayed in a bunch of TextFields as download report from a method called in the loop, I hope the variables are released), etc. NthField
The download code is 20KB (with tons of comments), I can optimize it a bit (use a single method/function to download the three dailies images (same url before the ? parameter part / Same file name, excepted for a suffix [-a, -b or -c]). But I optimize stuff once they works fine, not when there is trouble in the code.
I also can run it in the IDE (just in case there is some difference / I grab some precious information).
OK but my final question is “how many pictures do you load”?
If the year is 365 days, I will get 3 x 365 Pictures (if I take the whole year).
So, depending on the size of each picture, you get in the same problem as I was in.
Just try to load your pictures 20 a a time, then set a Timer to load the 20 next pictures and it’s gonna work
while I was writing (3 x 365) I realized that I can download a year in two times (and not having the trouble). I was not sure that it was not my fault