Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Holding collections in memory, good or bad idea?

Holding collections in memory, good or bad idea?

Scheduled Pinned Locked Moved Visual Basic
databaseperformancequestionannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jay Royall
    wrote on last edited by
    #1

    Hi, I have several collections which are used many times within my application. These collections (which are mainly generic lists) are collections of user-defined objects populated with data from a database, objects instantiated form classes such as regions, ethnicities, disabilities etc. Is it a good idea to build these collections when the application starts and hold them in memory while the application is running, or would it be better to build them when required then release them when done resulting in many database calls. Thanks in advance.

    M 1 Reply Last reply
    0
    • J Jay Royall

      Hi, I have several collections which are used many times within my application. These collections (which are mainly generic lists) are collections of user-defined objects populated with data from a database, objects instantiated form classes such as regions, ethnicities, disabilities etc. Is it a good idea to build these collections when the application starts and hold them in memory while the application is running, or would it be better to build them when required then release them when done resulting in many database calls. Thanks in advance.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Retaining the lists in memory, I do it all the time. How do you deal with the user adding to the list. I have a static class MasterTables with a property for each table, in the getter if there is no table I get the data from the database, this requires 1 call. If the user changes the master table data I simply set the mastertable property to null, next time it is requested a new copy is loaded. This gets away from the initial hit when starting the app, loading all those master tables can be a noticable delay on the load. I know it can be done in a non ui thread but the master tables style suits me admirably.

      Never underestimate the power of human stupidity RAH

      J E 2 Replies Last reply
      0
      • M Mycroft Holmes

        Retaining the lists in memory, I do it all the time. How do you deal with the user adding to the list. I have a static class MasterTables with a property for each table, in the getter if there is no table I get the data from the database, this requires 1 call. If the user changes the master table data I simply set the mastertable property to null, next time it is requested a new copy is loaded. This gets away from the initial hit when starting the app, loading all those master tables can be a noticable delay on the load. I know it can be done in a non ui thread but the master tables style suits me admirably.

        Never underestimate the power of human stupidity RAH

        J Offline
        J Offline
        Jay Royall
        wrote on last edited by
        #3

        Ok great, thanks for the tip, sounds like a good idea and one I will definately use :thumbsup:

        1 Reply Last reply
        0
        • M Mycroft Holmes

          Retaining the lists in memory, I do it all the time. How do you deal with the user adding to the list. I have a static class MasterTables with a property for each table, in the getter if there is no table I get the data from the database, this requires 1 call. If the user changes the master table data I simply set the mastertable property to null, next time it is requested a new copy is loaded. This gets away from the initial hit when starting the app, loading all those master tables can be a noticable delay on the load. I know it can be done in a non ui thread but the master tables style suits me admirably.

          Never underestimate the power of human stupidity RAH

          E Offline
          E Offline
          Ed Hill _5_
          wrote on last edited by
          #4

          One consideration to make, if you edit the data, your local copy is still valid, but if many users use the program and they have a locally stored copy that is different to yours things get out of sync. You can keep a record of when you last loaded the table from the database, and also a record in the database of the last time the data was updated. This will mean you have to check you have the latest version each time, which is a database call, but you will only get the data if it has changed since you last got it. Only really an issue with a multi user application.

          J M 2 Replies Last reply
          0
          • E Ed Hill _5_

            One consideration to make, if you edit the data, your local copy is still valid, but if many users use the program and they have a locally stored copy that is different to yours things get out of sync. You can keep a record of when you last loaded the table from the database, and also a record in the database of the last time the data was updated. This will mean you have to check you have the latest version each time, which is a database call, but you will only get the data if it has changed since you last got it. Only really an issue with a multi user application.

            J Offline
            J Offline
            Jay Royall
            wrote on last edited by
            #5

            Ok thanks, good point! It is a multi-user application, however the lists in question are probably not going to get modified very often. The lists hold data such as ethnicities, regions etc, which are fairly static. But thanks for pointing that out, something I hadn't considered but will bear in mind in the future :)

            1 Reply Last reply
            0
            • E Ed Hill _5_

              One consideration to make, if you edit the data, your local copy is still valid, but if many users use the program and they have a locally stored copy that is different to yours things get out of sync. You can keep a record of when you last loaded the table from the database, and also a record in the database of the last time the data was updated. This will mean you have to check you have the latest version each time, which is a database call, but you will only get the data if it has changed since you last got it. Only really an issue with a multi user application.

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              While this is what I call a "technical" issue I have not seen it become a problem in a practical sense (I also currently don't work on transactional systems either). I find that master file information is rarely updated once the system is set up and if I enforce a daily restart it pretty much eliminates the problem. I also tells the users it is a potential issues so they are aware of it.

              Never underestimate the power of human stupidity RAH

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups