Table of Contents Previous Section
Variables and Scope
Each kind of variable has a different scope and a different lifetime. Local variables are only visible inside the block of text in which they are declared. In the example above, localVariable1 is declared at the top of a method. It is accessible within the entire body of that method, including the while loop. It is created upon entry into the method and released upon exit. localVariable2, on the other hand, is declared in the while loop construct. You can only access it within the curly braces for the while loop, not within the rest of the method.The scope of an instance variable is object-wide. That means that any method in the object can access any instance variable. You can't directly access an instance variable outside of the object that owns it; you must use an accessor method instead. See "Accessor Methods".
The lifetime of an instance variable is the same as the lifetime of the object. When the object is created, all of its instance variables are created as well and their values persist throughout the life of the object. Instance variables are not freed until the object is freed.
- A WOApplication is created when you started a WebObjects application
- A WOSession is created each time a different user accesses that application during the component action request-response loop
- A WOComponent is created the first time a user accesses that page in the application
- A WODirectAction is created at the beginning of each direct action request-response loop cycle.
Note: Just how often a particular component object is created depends on whether the application object is caching pages. For more information, see "WebObjects Viewed Through Its Classes".
Table of Contents Next Section