Questions tagged [memory-management]

Memory management is the act of managing computer memory by allocating portions of memory to programs as well as freeing memory so that it can be re-used.

Filter by
Sorted by
Tagged with
1 vote
1 answer
2k views

Will this code get cleaned up by the garbage collector?

I have been working on a Backbone.js application, and I am starting to think I am making a huge mistake. I never fully understand garbage collecting, and how exactly some closures prevent it. I just ...
Saif Bechan's user avatar
3 votes
1 answer
2k views

Java: Find the smallest integer not in the list - Memory Efficiency

This is a fairly popular interview question that I conceptually understand but have never really attempted to implement. In other similar implementations of this in Java I have seen they typically ...
maple_shaft's user avatar
5 votes
2 answers
8k views

Min Heap implementation with Dijkstra's algorithm

I am implementing Dijkstra's Algorithm using Min Heap to speed up the code. For a small number of nodes, the code is really running very fast. But for a large number of nodes, my code is throwing ...
ravi's user avatar
  • 429
1 vote
1 answer
1k views

Free memory outside function

Is this going to leak memory or is it ok? Please also let me know if there is something else that I need to pay attention to. ...
user avatar
1 vote
1 answer
255 views

Variable sized type allocation

I have a type that receives serial data over a pipe: struct Packet : Base { // Base is POD, too int foo; char data[]; }; In the context, where I instantiate <...
bitmask's user avatar
  • 175
4 votes
1 answer
381 views

Is this a valid usage of structure assignment in C?

Q: Please comment on the usage of structures and structure assignment operations in C I am working on converting a MATLAB program to C using BLAS and LAPACK for linear algebra support. The MATLAB ...
mod0's user avatar
  • 43
3 votes
2 answers
2k views

Read until EOF and realloc as needed

This is a function that reads until EOF and reallocs as it goes. ...
knc's user avatar
  • 31
3 votes
2 answers
3k views

Tree Node class - deallocation in the destructor

Is my destructor correct? Does it properly deallocate the subtrees? ...
Worryn Ashtrod's user avatar
5 votes
1 answer
1k views

Simple TCP client - memory issues

Does this snippet take too much memory? How can I let the connection opened with the function connectTo outside the forever loop? ...
jinkou2 jinkou2's user avatar
2 votes
1 answer
326 views

Am I using my data source array correctly?

When I want to make some quick tests for my UITableViewControllers, I usually create an NSArray that holds some dummy data. I would like to know if I'm doing anything wrong here: First in ...
phi's user avatar
  • 155
3 votes
1 answer
3k views

Space to allocate before sprintf

I just finished chasing a Heisenbug that was entirely my fault. I'd like to avoid it happening again. I have a function which formats a date to a certain preset format. Turns out I was not allocating ...
MPelletier's user avatar
5 votes
2 answers
930 views

Human (imperfect) array (card) shuffle written in C

I've got this humanoid_shuffle I wrote in Python. I've been wanting to learn C so as an exercise I ported it to C. As this is my first venture into C and even the ...
jondavidjohn's user avatar
3 votes
1 answer
909 views

Memory leak in a scraper [closed]

This is a scraper written in CoffeeScript for NodeJS. It is run in an interval (set to 5 seconds here to dramtically show the leak). Somewhere this code leaks memory. I already tried nulling a few ...
Lincoln's user avatar
  • 139
7 votes
1 answer
707 views

Memory issues with Find Strings Problem on InterviewStreet

Here is the code I wrote for the problem at http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4efa210eb70ac where we need to to print the substring at a particular index from ...
S P's user avatar
  • 205
6 votes
1 answer
296 views

Is this a good algorithm for 2D collision, or will it allocate too much memory?

I have a Rectangle class, of which I have 5-6 vectors for each instance. The main vectors are the center and color of the object, while the secondary vectors represent more or less the north, south, ...
Holland's user avatar
  • 179
4 votes
3 answers
779 views

Simple, lightweight deterministic "garbage collection"

I am toying with a simple class to inherit from to manage my dynamic resources. I am fairly new to C++, so my "implementation" might be suboptimal. Suggestions how to improve functionality are welcome....
dtech's user avatar
  • 161
3 votes
1 answer
181 views

Am I managing my memory correctly?

I read that if an object is made using the init it must be released, but if it's something like this ...
Mahir's user avatar
  • 361
6 votes
3 answers
835 views

App for allowing the user to type in chemistry formulas using a custom keyboard

Essentially, I am making an app that allows the user to type in chemistry formulas using a custom keyboard. The keyboard will have several keys, for example, "Na", "H", and "O". Pressing them in ...
Mahir's user avatar
  • 361
9 votes
1 answer
4k views

Super simple templated memory pool in C++

I have a small program where I have a background thread that plays sound, so it needs to run really fast, but it also needs to do a small amount of memory management. I didn't want to use normal new ...
Alex Ames's user avatar
  • 463
2 votes
1 answer
495 views

Runge-Kutta 2nd order of differential equations

Could I improve this somehow (not numerically, just C-wise)? Do I need to allocate the array since I am returning it and not just using it inside the function? ...
user avatar
11 votes
3 answers
2k views

Reusing strings read from I/O

I am working on an application that reads lots of data from the network and puts it in a grid. I noticed that I could save some memory by reusing existing strings instead of always using the new ...
Chris's user avatar
  • 213
4 votes
2 answers
213 views

Array initialization from text string

I have a block of text where several arrays are printed out, with a name and values: VAL1=10 20 30 40 50 VAL2=4 8 15 16 23 42 I have a function that looks for the value name, and sets an array of ...
MPelletier's user avatar
7 votes
1 answer
730 views

Double-Ended Queue - Have I over-engineered it again?

I'm working on an implementation of the Double-Ended Queue as a Doubly-Linked List (for personal enrichment), and I was wondering if anyone minded taking a look at my Constructor/Destructor and Empty ...
wtfsven's user avatar
  • 221
3 votes
1 answer
337 views

My program spikes from 100,000K mem to 1,000,000K mem in a matter of minutes in my program in VB.net [closed]

I've created a program that uses System.Graphics to render a simple (small) 2D scene to the screen. The problem is, for some reason, it starts to quickly ...
Freesnöw's user avatar
  • 141
1 vote
2 answers
334 views

NSAutoreleasePool with Json Data

Just need to know if I'm doing something wrong in this code. my app seem work fast now with this code. I just want to if i really understant that ...
user avatar
5 votes
1 answer
304 views

Overloading the new operator

This may be a naive question, but what are the dangers of the following code (allocate more memory in the new operator for the info struct)? ...
themadme's user avatar
3 votes
1 answer
1k views

Does this I/O operation caused a memory leak [closed]

My colleague did some code Optimise work. Code below is from a public method of a public class (NOT STATIC CLASS OR METHOD) code before: ...
ValidfroM's user avatar
  • 187
3 votes
1 answer
2k views

Memory leaks in lottery simulator

I'm primarily a C++/Java programmer, but I've recently started using Python at work and decided to write a Lottery Simulator at home. I wrote it to test out different combinations of lottery numbers ...
Chris Just's user avatar
8 votes
2 answers
2k views

BitTorrent peer protocol messages

I'm writing a BitTorrent client. Part of the protocol is an exchange of length-prefixed messages between peers. The forms of these messages are described in the official specification and also in the ...
R. Martinho Fernandes's user avatar
2 votes
1 answer
603 views

Memory Question

Can this part of a view controller subclass be checked for memory leaks. I am not that good at finding leaks. I need this class to be able to be loaded many time over without it crashing due to memory ...
iPhoneDeveloper's user avatar
3 votes
0 answers
1k views

Integrating SFML and Box2D lib, and a Mass Production Shape Factory [closed]

I've just written two new headers: one that integrates Box2D and SFML by a class called BodyRep which creates/ is a graphic representation of any body, and one that ...
Griffin's user avatar
  • 297
8 votes
1 answer
568 views

Use of external memory or a custom allocator

I'm creating a class which uses a custom buffer. I want to offer the possibility to pass an external memory address (for higher interoperability between languages) or (for convenience) to specify a ...
0xbadf00d's user avatar
  • 300
4 votes
2 answers
3k views

Allocating memory for a matrix with a single malloc

For an interview, I was asked to write code allocate memory for a rows*cols matrix, using a single malloc(). I want your comments about this code that I wrote: <...
Ganesh's user avatar
  • 339
2 votes
2 answers
2k views

Subclassing UIButton

I need to subclass UIButton, however the design of UIButton makes this really painful. This is because to create a button you ...
Ian1971's user avatar
  • 133

1
9 10 11 12
13