0

I'm having trouble with a clear statement. I've got an array that gets sized dynamically, filled, and then passed to a function to be converted to some custom objects.

After that conversion I want to clear the array. I use

Array.Clear(FileData, 0, FileData.Length)

as this thread suggests (reset-an-array-to-default-in-visual-basic). However, every time I get to that point in the script the try-catch wrapping the Clear catches an out of bounds exception on the Clear.

The array is not empty (actually it's got ~34900 items) so it's not that the array has zero length. The one thing that it might be that isn't discussed in the question I referenced above is that my array is 2 dimensional.

All that said, I'm fairly well stumped. Any help would be appreciated.

UPDATE: For those experiencing this issue, I ultimately just left the step commented out, so that instead of clearing and then setting the array to Nothing, I just set it to Nothing. Doesn't really solve the underlying issue, but (should) free up memory all the same.

Community
  • 1
  • 1
JMichael
  • 157
  • 3
  • 14
  • What is each of its dimensions? – Ry- May 12 '14 at 20:48
  • Unknown. The array of arrays is used to take in the data from a CSV whose number of columns and rows varies (our customer doesn't manage the db that generates the CSVs very well). So to deal with their craziness I find the "corners" of the data in the CSV, and then dump the whole thing into FileData. I then convert each element in FileData into a specified object so that everything is all nice an cleaned up for import to a relational db that we have – JMichael May 12 '14 at 20:57
  • Are you using multiple threads? That's the only explanation I can come up with. And as David mentioned in his answer. If you need resizable stores, consider using generic lists. – Nico Schertler May 12 '14 at 20:57
  • No threading (no where near good enough to be messing with threading). Lists are out due to the fact the column orders can change, from one dump to the next. I do throw the objects created from each element into a list – JMichael May 12 '14 at 21:00
  • Approximately, I mean. – Ry- May 12 '14 at 21:00
  • Could you please add the declaration of `FileData`? – Nico Schertler May 12 '14 at 21:02
  • Is `FileData` a jagged array? – Andrew Morton May 12 '14 at 21:40
  • minitech: It's pretty hard to say, in some instances the dumps come in 5 chunks, other times it's one massive file. In the first instance, some chunks are as small as 200-500 elements in FileData and others are 1000+. In the one file scenario there are ~3000 rows in the CSV. ANDREW: Probably not, but I've not done the checking to be sure. NICO: FileData is declared as a Public Property of an object I use to ferry data throughout the script: `Public Property FileData as Object(,) = Nothing` – JMichael May 12 '14 at 21:47
  • For those who come across this thread in the future, I still haven't figured out an actual solution. All I did to get past the problem was to comment out the Clear statements and simply set the array to Nothing. – JMichael Aug 25 '14 at 19:54

0 Answers0