Questions tagged [object-initialization]
56 questions
1
vote
4 answers
Garbage Collection on objects not assigned to a variable
I am working on project that uses this pattern
var businessEntity = new DAL().GetObject(id);
// do something with the business entity.
Has anyone followed this pattern?
Does this cause any memory management issues? Any complications with the…

Nick Harrison
- 921
- 9
- 17
1
vote
2 answers
Differences between these two List initializations in C#
I am going through some C# training and am trying to understand the difference between these two List initializations. I have not had much luck finding a good explanation.
When I debug, both show a count of 5. The first shows a capacity of 5…

HKstrongside
- 333
- 1
- 7
1
vote
3 answers
Initialization of Array Objects With Parenthesis in C++
Here there is a class with two private fields x and y;
class Point
{
private:
int x, y;
public:
Point(int = 1,int = 1);
void move(int, int);
void print()
{
cout << "X = " << x << ", Y = " << y << endl;
}
};
When…

Levent Divilioglu
- 11,198
- 5
- 59
- 106
1
vote
1 answer
In c#, does object initialization syntax happen before assignment?
In c#, does an object initialization like:
var thing = new List

Cirdec
- 24,019
- 2
- 50
- 100
1
vote
6 answers
How do I make the C# constructor syntax more pythonic?
I have some background in the python initializer (essentially Python object constructor syntax), and the syntax to instantiate an object in Python is as follows:
class Account:
def __init__(self,name=None,address="Not Supplied",balance=0.0):
…

Jack_of_All_Trades
- 10,942
- 18
- 58
- 88
0
votes
2 answers
C++ how to declare a "complex" object inside a loop?
edit: As mentioned by @HolyBlackCat
"If you need it to retain it's [a variable's] value between iterations, it has to stay outside." This is of course true of even primitive types, eg. int. So this question is actually just noise, sorry.
I'm trying…

mrchance
- 1,133
- 8
- 24
0
votes
1 answer
How to identify / get automated hints with cyclic object initialization causing deadlocks in Scala?
The following code runs into future timeouts (in Scala 2.x and Dotty, -Xcheckinit or -Ycheck-init does not help here) because of cyclic object initialization. In complex projects these cycles usually are hidden very well. Is there any possiblity of…

Chris W.
- 2,266
- 20
- 40
0
votes
1 answer
PowerShell - Class Attribute is second Class but not getting any values for their attributes
I have one class with default value for Status Message:
class DeploymentState {
[string] $StatusMessage
DeploymentState() {
$this.StatusMessage = "initial status."
}
}
I have Second Class which references the first…

vel
- 1,000
- 1
- 13
- 35
0
votes
1 answer
Object initialization in Java using Dependency Injection
While trying to understand the Dependency Injection principle I came across this example which I couldn't understand
abstract class ExternalInvestmentBase {
private static ExternalInvestmentBase sImpl;
protected ExternalInvestmentBase()…

RangerReturn
- 171
- 3
- 3
- 18
0
votes
2 answers
Initialization of a JavaScript/ES5 object using a constructor with Getter/Setter
The following constructor function is written in JavaScript / ES5 -
function Range(from, to) {
function getFrom() { return from; }
function getTo() { return to; }
function setFrom(f) { from = f; }
function setTo(t) { to = t; }
…

atiyar
- 7,762
- 6
- 34
- 75
0
votes
1 answer
vb.net create objects in for each loop from partial info in Ienumerable
Summary:I want to create objects in a for each loop.
I have a class - Dashboard, which has some properties - length, height, etc.
This info is contained within an XML document, but my class' properties is only a small subset of the information in…

ThomasRones
- 657
- 8
- 29
0
votes
2 answers
Initialize instance of singleton descendant
In a traditional singleton, you can initialize the instance like so:
private static readonly Messages _instance = new Messages();
Then you access it via a getter, like so:
public static Messages Instance {
get {
return…

BWhite
- 713
- 1
- 7
- 24
0
votes
2 answers
How to initialize and return an object in a single line
I am trying to create Option objects based on the following typed interface:
interface Option {
/** Text for rendering */
label: string;
/** Value for searching */
value: string | number;
/**
* Allow this option to be…

Erwin Mayer
- 18,076
- 9
- 88
- 126
0
votes
1 answer
Object Initalization in AbstractTableModel
I am working on a small programm that should display recipies in a JTable.
All seems to work fine, the only problem I've got is that I can't initialize the object that should hold the data properly. Here's the class that gives me headache:
class…

ALMA
- 1
- 1
0
votes
3 answers
Passing an instance to a method Vs. forwarding parameters
I often encounter situations where I pass instances as parameters to functions. It occurred to me that it is equally possible to forward the parameters of the object instead, and initialize within the method.
Example:
class MyCanvas extends…

bigcodeszzer
- 916
- 1
- 8
- 27