memory-management

Recycle-safe thread ID's and when thread stack gets freed?

Does the stack reserved/commited for a thread get freed when the thread terminates the thread object is destroyed (i.e. the thread is terminated and all handles to the thread are closed) ? More broadly, are there significant resources associated with a thread that has terminated, but still exists since there are valid handles to it...

removeFromSuperview and memory management

Hi guys, I'm new to objective-c and at the moment developing a small application. I have some memory management issues and want to ask this particular question. I have a button, appearance of which I'm changing: for (UIView *subview in button.subviews) { if (![subview isKindOfClass:[UIImageView class]]) // don't remove UIImageView, ot...

High %wa CPU load when running PHP as CLI

Sorry for the vague question, but I've just written some php code that executes itself as CLI, and I'm pretty sure it's misbehaving. When I run "top" on the command line it's showing very little resources given to any individual process, but between 40-98% to iowait time (%wa). I usually have about .7% distributed between %us and %sy, wi...

Memory Issues: simulated memory warning/didReceiveMemoryWarning

App has 4 view controllers; Menu, A, B and C, and a singleton class to hold data in 4 arrays that are written to disk at app termination. A selection from the Menu creates an instance of A, "a"; a selection from "a" creates an instance of B, "b", and from "b", a selection bring up a modal data entry view "c". I simulate a memory warni...

Vectors within classes: handeling copy constructor and destructor (C++)

Take a simple class with the "big 3" (constructor, copy constructor, destructor): #include <vector> using namespace std; //actually goes in the C file that links to this header file ... class planets(){ //stores mass and radii data for planets in a solar system. public: vector <double> mass; vector <double> radius; //...

problem when I release my object

Hi I have a class whit a nsmutable array instance variable, In my code, I alloc and init my object, and later in my program I release my object, but it cause a "bad access" when I try to release it, why? If i retain my object before release it works, but I don't have other object who point on this object, so I don't need a retain. Alex ...

iPhone - Memory Management - Am I creating and releasing this variable correctly?

Ok heres the situation. I have a View controller class that serves as the main view(MainView). It contains a subview that another view controller takes care of(ChangingView). Now, every four seconds, ChangingView needs to change its view. What I am currently doing goes something like this. ChangingView = [[AnotherView alloc] initWithN...

Subtle memory management issue in Objective C

I recently (after hours of debugging) tracked down a segfault in an Objective C iPad app. To boil it down, I had an object TOP which owned MIDDLE which owned BOTTOM. MIDDLE and BOTTOM had retain counts of 1. MIDDLE passed BOTTOM to a method in TOP which ended up releasing MIDDLE, thereby causing BOTTOM to be released and dealloc'd. W...

iphone memory management (basic)

Very basic question about iPhone memory management: Say I have a viewController with several subviews also controlled by viewControllers. When I remove the top viewController and release the instance - what happens to its children? Are all the therein contained objects released as well? When I run my app in instruments, I don't get any...

When to retain in objective C?

I have been writing objective c for couple of weeks. However this question still bothers me a lot. Can anyone explain in pain english: When to retain an object? Thanks ...

Why Does Looping Beat Indexing Here?

A few years ago, someone posted on Active State Recipes for comparison purposes, three python/NumPy functions; each of these accepted the same arguments and returned the same result, a distance matrix. Two of these were taken from published sources; they are both--or they appear to me to be--idiomatic numpy code. The repetitive calcula...

IPhone watchdog & malloc

Hi! My app is using quite a bit of memory and therefore it's often get killed by the watchdog. In my efforts to reduce memory consumptions (and change some other stuff too) I've rewritten some of the system functions (replaced few CoreText classes to be exact). That actually went pretty well and I've managed to reduce memory consumpt...

Trying to understand memory management on the iOS platform

Hello. Here's a block of code that has leaks... NSString *filename = [NSString stringWithFormat:@"%@.png", sketchID]; CGImageRef imageRef = CGBitmapContextCreateImage(paintView.canvas.mBitmapContext); UIImage* image = [[UIImage alloc] initWithCGImage:imageRef]; NSData* imageData = UIImagePNGRepresentation(image); Where are they? In...

How can I decommit a file-mapped page?

I have a memory mapped file, and a page in a view which is currently committed. I would like to decommit it. MapViewOfFile tells me I cannot use VirtualFree on file mapped pages. Is there some other way to do it? ...

Python - Threaded program seems to have a Memory Leak?

I am writing a python program that seems to be leaking memory. The program takes in a list of URL's and makes sure their status code is 200. If the status code is not 200, then the script will alert me via email. The script threaded so the URL's can be checked in parallel of each other. I have set the program on a one of our server...

Why is Instruments reporting memory leaks in this code?

Quick question, Instruments is reporting a leak here... MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"myView" bundle:nil]; [self.navigationController pushViewController:myVC animated:YES]; //<<<<---- !00% leak according to Instruments [myVC release]; I understand the myVC is retained by the nav controller,...

Efficient use of large amounts of text in UITextView

I have a plist (array of dictionaries) with 20 items, each of the 20 dictionaries having a 'code' and 'text'; each text averages 1K bytes. The class that uses the text will use 1 of the 20, based on the 'code'. The text doesn't change so I'm keeping it in the bundle. I'd like to know if I'm doing this as efficiently as possible, basic...

use aio_write() but still see data going through cache?

I'm playing with this code on Linux 2.6.16.46: io.aio_fildes = open(name, O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, 00300); io.aio_buf = buffer; io.aio_nbytes = size; io.aio_sigevent = sigev; io.aio_lio_opcode = LIO_WRITE; aio_write( &io ); This should use the memory pointed by buffer for the IO operation. Still, I see the number of di...

Objective-C static "constructors" - do I need to retain?

I know that if I get an object, for example an NSArray, with a method like [NSArray array], it will be autoreleased. So I don't have to do a release myself. My question is, do I have to retain it after I get it this way? I wouldn't have thought so, since the count starts at 1 and it won't be released until the pool is released, but I've ...

Android setBackgroundResource release memory?

Hi, I have 2 quiet big Animations each 50pics a 20kb Both defined as Animations .xml One I let start from the beginning and the second after a button click. //Start immediatly imgView.setBackgroundResource(R.layout.anim1); rocketAnimation = (AnimationDrawable) imgView.getBackground(); //Start after button click img...