Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a static object the same object in multiple running applications?

If you have a windows service and a windows forms application that uses the same static object, is it the same object in both applications? In other words if I update the object in the service will it also be updated in the forms application as well if both are running at the same time?

like image 315
Crackerjack Avatar asked Apr 04 '12 17:04

Crackerjack


People also ask

Is static variable same for all instances?

Static variables are, essentially, global variables. All instances of the class share the same static variable.

What are static objects?

A "static" object is unique; it belongs to the class rather than the instance of the class. In other words, a static variable is only allocated to the memory once: when the class loads.

What are static objects in software engineering?

Static objects are declared with the keyword static. They are initialized only once and stored in the static storage area. The static objects are only destroyed when the program terminates i.e. they live until program termination. A program that demonstrates static objects in C++ is given as follows.

How many possible copies can a static have?

Only one copy of a static member exists, regardless of how many instances of the class are created.

Are static variables Part of the objects State?

Class is known as the class level object and static variables are called class variable because static variables lie as the state of the class level object.

What is the use of static object in Java?

The static variable can be used to refer to the common property of all objects (which is not unique for each object), for example, the company name of employees, college name of students, etc. The static variable gets memory only once in the class area at the time of class loading.


2 Answers

They run on different processes so they don't share the static object.

Not exaclty related with your question but threads created on the same application is a different story. They will share the static variable unless is marked with ThreadStatic attribute

like image 79
Claudio Redi Avatar answered Nov 06 '22 12:11

Claudio Redi


No. Unless you do something specific to achieve this objects are not shared between different processes.

like image 21
Brian Rasmussen Avatar answered Nov 06 '22 11:11

Brian Rasmussen