Adobe Interview Question
Software Engineer / DevelopersCountry: India
try {
HashMap map = new HashMap();
while(true){
map.put(RandomNumber(),RandonMumber());
}
}catch(OutOfMemoryException e){
s.op( " MemoryIsFull" )
}
HashMap h = new HashMap();
h.put("hi","hello");
/* since there was no more memory... and now im able to add a new value into it, it means the memory is freed and im able to use the memory, In java Garbage collector does this, in C,/c++ you do it..... just hte difference is, allocate some high value tll it give outofmemory, then free and allocate memory again */
I think the question says to check whether the memory given to the program is returned at the end to the OS. In other words, the memory available to the program at the beginning should be equal to the memory available at the end. There should be no memory leakages. The program should check this. It can be done by repeatedly allocating memory, until an out of memory error is received - keeping track of no. of bytes allocated. now, free the memory and allow program to proceed. At the end of the program, the exact no. of bytes that were allocated (at the start) should be available
I think the interviewer here just wants you to overload you new & delete and also provide some query interface which tells at any point of time amount of memory used by the program using new. The stack shall always get clear when the program stops so that is not concerned. Only dynamic allocation was being tested by this.
I think the interviewer here just wants you to overload you new & delete and also provide some query interface which tells at any point of time amount of memory used by the program using new. The stack shall always get clear when the program stops so that is not concerned. Only dynamic allocation was being tested by this.
I think the interviewer here just wants you to overload you new & delete and also provide some query interface which tells at any point of time amount of memory used by the program using new. The stack shall always get clear when the program stops so that is not concerned. Only dynamic allocation was being tested by this.
i think in this what we can do is we can allocate some memory for variable in class inside constructor .. and then we can print the sizeof memory allocated .... in main we can delete on the same object pointing to the class ... in the destructor code we can again print the sizeof memory getting deleted ..... both should be same ...
in java you can do that,
Runtime runtime = Runtime.getRuntime () ;
At the starting of your program:
Do,
And when you finish your program just check the same! And compare!
- Psycho September 25, 2012