Wipro Technologies Interview Question for Technical Architects


Country: India




Comment hidden because of low score. Click to expand.
1
of 1 vote

For dynamic memory leaks:

In C++:
We can override new, delete operators. We should also make sure to override new[] and delete[] operators. The override methods, internally call C++ built-in routines, plus do tracking. By tracking I mean:
- On new (and new][]), we add the memory pointer (if not null) to a hash table
- On delete (and delete[]), we remove the entry in hash table.

When the program terminates, one can check the hash table contents. If the hash table is empty, then there are no leaks. Otherwise, there are leaks. We can also check double-free/double-deletes in this override model. When someone deletes a pointer, and the entry does not exist in hash table; it means it is either a random address are double-free.

Similarly, in C:
We can write our own malloc and free functions Ex: mymalloc and myfree. These routines are same as the routines mentioned above. The only catch is that we have to expect every allocation to use these my* methods than built-in methods. If your C compiler supports function/method overrides, you could override malloc and free as well.

For static memory leaks:
I am assuming you meant to say 'unused' variables. By unused, they are either not initialized or initialized but never used (never participated as R-Value, OR, always appeared as L-Value). This is done using code parsers. Here we have to write C language parser much like compiler. And do a static analysis of code.

Thanks,
Laxmi

- Laxmi Narsimha Rao Oruganti November 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There are various approaches you can take but before you embark on the journey, you need to make sure that there's a memory leak to begin with.

Once you are sure, you could use tools like leakdiag or IBM purify to see the stack trace of possible leaks (this is not guaranteed though). You may find the area of leak or may not. But Idea is to narrow down the scope. Once you have where the memory leak is.
Now, you need to jump and see what exactly you aren't freeing (this step is different depending on code base) Wrapping your resources around shared_ptr might be a good way to avoid memory leaks. Solving memory leaks are arduous and painful to the least. try to avoid it by all means.

- intermediate engineer November 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question was to write some piece of code which can identify the memory leak , may be something like Garbage Collector. And the question was like suppose there is one program which crashes during runtime and core is getting generated in unix env how wud u find out the memory leak.

- Anonymous November 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One way is log your reference count, increase when new object is created or decrease when you destroy and if it crashes / terminates, you can check your log file. When refcnt = 0, no memory leak, else memory leaks.

- Anonymous November 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi,
We can use Valgrind tool that is generally used for memory leak.we can install that patch in unix .it will simply work with all memory leaks

- nitin gupta November 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can also use "ps -augx" command in unix, and can check the RSS (Resident set size) value.

- James February 09, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More