Questions tagged [lifetime]

A variable's life-time is the time during which the variable is bound to a specific memory location. The life time starts when the variable is allocated and ends when it is deallocated.

Most of the time a lifetime is a synonym for the scope, for example in this code:

void foo()
{
    int x = 0; // lifetime of `x' begins here ──┐
    //                                          │
    printf("%d\n", x); //                       │
} // and finishes here ─────────────────────────┘

Rust:

The lifetime is a key concept in : it is a construct the compiler (also called the ) uses to ensure all borrows are valid.

Links:

2138 questions
1
vote
1 answer

Finding a way to solve "...does not live long enough"

I'm building a multiplex in rust. It's one of my first applications and a great learning experience! However, I'm facing a problem and I cannot find out how to solve it in rust: Whenever a new channel is added to the multiplex, I have to listen for…
1
vote
3 answers

Lifetime of array defined in a javascript method

Consider the following javascript code. function myFunction() { var myArray = []; myArray.push("hello"); return myArray; } var isValid = myFunction(); Is the return value referring to a stack variable myArray that is lost when…
winterlight
  • 460
  • 4
  • 10
1
vote
1 answer

PHP - session_set_cookie_params(), lifetime doesn't work

As first, I know a lot questions are like mine, but I really don't know what I'm doing wrong... As you might've guessed, I've a PHP script involving sessions. Everything works like a charm, except setting the lifetime of my session. I want to keep…
Isaiah
  • 1,852
  • 4
  • 23
  • 48
1
vote
1 answer

I am confused about servlet instance

The Request Handling section of the Servlet spec says "Note that a servlet instance placed into service by a servlet container may handle no requests during its lifetime"... What does this mean?
huashui
  • 1,758
  • 2
  • 16
  • 24
1
vote
0 answers

UILocalNotification expires?

I have an App based on UILocalNotifications. By documentation, if notification for some reason hasn't been fired (for example iphone was off), then it should fire immediately as iphone is turned on. In my case it has not fired. I had my phone turned…
1
vote
2 answers

Database Context and asynchronous functions in MVC 4 / EF 5

I did not find similar questions/answers for my purpose. In few Actions of my Controllers (MVC 4/ EF 5 application) I have functions for updating of database, but these functions are not affect on user output (functions of updating information after…
1
vote
1 answer

Race condition when cancelling tasks during app deactivation

I'm trying to use Task-based asynchronous pattern in my Windows Phone 8 app. Idea is that all long-running operations have reference to a cancellation token, and there's one place in app where all those tokens are stored. When app receives…
Haspemulator
  • 11,050
  • 9
  • 49
  • 76
1
vote
2 answers

PHP - Do you need to set the session data again to reset the lifetime?

...or do you only need to start a new session? I've been given the task of fixing a bug that causes sessions to expire even though the session.gc_maxlifetime is set to 8 hours (It does get set, i've checked). After going through the code, i noticed…
qwerty
  • 5,166
  • 17
  • 56
  • 77
1
vote
3 answers

deallocation after scope has ended

Possible Duplicate: Returning the address of local or temporary variable Can a local variable’s memory be accessed outside its scope? Suppose we have the following code int *p;//global pointer void foo() { int a=10;//created in stack p =…
nutr0n
  • 11
  • 2
1
vote
2 answers

Will (global) static variables be destroyed at program end?

Possible Duplicate: Does C++ call destructors for global and class static variables? What is the lifetime of global MyClass myclass; global static MyClass myclass; global const MyClass myclass; global static const MyClass myclass; function local…
towi
  • 21,587
  • 28
  • 106
  • 187
1
vote
3 answers

How to cope with lifetime of returned pointer?

I am making a set of classes to represent an image. One of the applications of this class will be to draw a picture over a set of tiled images. The abstract image class looks something like this: class Image { public: virtual Pixel* findPixel(…
user487100
  • 918
  • 1
  • 11
  • 22
1
vote
1 answer

Multiple project Solution Object LifeTime

I admit I'm a newbie for C# and I have the following question. Assume you have a solution with three projects (A, B, C). Project C references B, and both B and C reference A. B is where the entry point is. I have a list in one of the classes within…
user1376971
0
votes
3 answers

How can I guarantee an object's lifespan matches the duration of a member function?

I've been making use of callbacks to reduce coupling between some C++ classes. To define terms: I'll call the class making the callbacks the caller, and the class receiving the callback the callee. Typically (but not necessarily), the callee will…
Matt Wilding
  • 20,115
  • 3
  • 67
  • 95
0
votes
1 answer

One-or-nothing implementation in MEF container

How do I make sure that the container was either an instance of the class, or it was not, depending on whether there is a link to it or not. I using MEF container, C# Edit: In other words, I need the ability to manage the lifetime of objects Shared…
Ivan
  • 173
  • 1
  • 4
  • 18
0
votes
3 answers

Java Scope and Lifetime (inner classes)

I need to explain why the following code would fail to compile (in terms of scope and lifetime): class ClassInMethod { public static void main(String[] args) { int local = 1; class Inner { public void method() …
tommy1370
  • 133
  • 1
  • 2
  • 10