Out Of Memory Error on dictionary declaration

While working on my very first Garmin project I'm getting this error Error: Out Of Memory Error
Details: Failed invoking <symbol>

I think this happens because I'm trying to declare a dictionary from an extreamly long string. It has more than 5500 characters. I generated this string from a json file using python because I want to make my data field run on a forerunner 235 and I found out that this device can load resources because of the limited api level. So I decided to just generate an .mc file with the array in it. All looks good though.

Why can't I create a dictionary like this? Is there an other way to get this data into my app? 

  • Loading a single string from a string resource and then parsing it wouldn't that throw a out of memory error again while trying to parse the string since you need to have the whole thing in memory to?

    Yeah, you're right. I guess it all depends on whether you have more memory available to your app at init time compared to after init time (e.g. if you have some other structures which don't exist at init time.) If you have some spare memory at init time, you can temporarily load the string and use it to create your preferred data structures. But if you're already running out of memory at init time, then it obviously won't help.

    My suggestion really only makes sense if you can load and parse the string resource on demand, but never save *all* the data to another structure. But this would be pretty slow.

    So the way I used this technique was to use a string resource as a lookup table during init. This is for an app that parses a math formula (kinda like Excel).

    Every time I needed to look up a text symbol, I would parse the string on demand. This was extremely slow but it did save memory. But it did open me up to issues where the app would crash due a watchdog timeout, for large formulas.

    The way I suggested doing things for you (parsing the string and saving all the data into the structures you want), doesn't make much sense, under further scrutiny.

    The only way you could save memory by using a string resource is if you only ever used it for lookups, but never translated all the data into your preferred data structures. However, that would be pretty slow.

    Plus in this case, as Jim pointed out, the string representation of your array will be even bigger than the array itself, because of the float values.

    In your case it probably just makes more sense to have your data in the app itself (but perhaps wrapped in a function so it only consumes memory when you need it. If you use it all the time, then there's no point in wrapping it in a function.) This is actually the approach I've taken for most of my apps.

    - Old devices: just have data in app (possibly wrapped in function)

    - New devices: use JSON resource. (This freed up memory for more features)

    Sorry for the bad advice haha.

  • I think it's good to look in multiple directions so I wouldn't call it bad advice. Smiley It was quite interesting trying all this stuff out. Thanks for the links. That will certainly help continuing my quest to get my data field to work on my good old 235.