开发者

Have a class with Static members

I have created a class that has ~12 static memebers and 2 arrays with ~1500 integers stored, so that whenever i need them while coding, i call the class and get the member i want.

I was wonderi开发者_开发知识库ng if this is a bad thing to do.. do those Static members stay in memory the whole time? is it a bad thing to have a 2 static array with ~1500 integers?

I'm asking those questions because my app uses 22mb of RAM! which is a lot and thought this could be a reason, so can having this static class be the reason of all this ram? Is there a better way to handle this? Thanks.


If I was storing that much information, I'd put it in a SQLite database.


22Mb of RAM is too much, your app will surely crash on devices with low OS versions. I can't see the reason of storing 1500 integers in memory, you can try storing them in XML and loading them when needed. Check this link to know how to store values in an XML file: Providing Resources


Static members of a class are in memory for the entirety of the program's execution, and yes they stay in memory the whole time, that is how you access them whenever you want. I can't really answer your question about arrays because you didn't post a lot of information about your project, it may or may not be a good idea based on what you need to do.


Omar,

 First of all. Why do you have to use array with 1500 integers in it when clearly you have better techniques to store data. Like Egor mentioned, you can use XML as well, but then, you have to choose the right technology in that as well since DOM will load everything in memory and you'll end up in the same situation.

The best way is to store all this information in a DB and retrieve the appropriate data whenever you want. Moreover, use static members only when you need it(like using a constant) which is a good practice.


2 Arrays of 1500 integers, wont take up space upto 22 MB. There is something wrong in your app. Such an array will take only less than 50KB, So 2 arrays should be around 100KB. So what are the other static members?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜