How to keep an object in memory in Scala? -


is possible in scala create object , keep in memory? hope question doesn't exist yet. have not found scala specific @ least.

the problem is, want read csv file of zip code data of country (it's not big, should fit memory) , store zip codes , corresponding cities object (e.g. map zip code key , citi(es) value). later want search specific zip code in object. if exists? , if want give out corresponding citi(es). don't want read in csv file again , again every time call function. that's why want keep data object in memory. there way in scala that? how can check if object exists in memory or if have create it?

does has hint should for?

after create map, remain in memory until garbage collected. if no objects reference map, garbage collector delete it. can either pass reference map around program never deleted, or make static.

in java put static member in class - parallel in scala put in singleton object may this:

object storeddata {   lazy val data : map[...] = // read file } 

you can read calling storeddata.data anywhere in program.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -