Questions tagged [alloc]
207 questions
3
votes
2 answers
init] in automatic reference counting
I know that I am suppose to use:
ObjectClass *tmpObject = [[ObjectClass alloc] init];
realObject = tmpObject;
[tmpObject release]
to initialise realObject (where realObject is an object within a class)
But now with ARC mode, releasing is automatic,…

Tim Purple
- 100
- 1
- 8
3
votes
3 answers
Can I return allocated object and release it outside function?
- (NSString *)allocString{
NSString *str = [[NSString alloc] init];
return str;
}
- (void)viewDidLoad{
NSString *name = [self allocString];
[name release]; // Can I release an object here?
}
Hi, I just wrote a simple example using…

pnmn
- 1,127
- 1
- 14
- 22
3
votes
3 answers
NSString alloc or not!
I am running this code from the scrollViewDidScroll method (so it runs when you scroll!):
NSString *yearCount = [[NSString alloc] initWithFormat:@"%0.1f", theScroller.contentOffset.y];
years.text = yearCount;
[yearCount release];
which works…

mtompson
- 261
- 3
- 21
3
votes
2 answers
How can I get an NSNumber without performing alloc on it, so it will respond to initWithInt?
My understanding is that a 'convenience' method such as [nsnumber initWithInt] should create a copy of the indicated class, initialized to the desired value.
minutesLeft=[NSNumber initWithInt:((timeLeft)%60)];
Timeleft is an integer, so initWithInt…

RonLugge
- 5,086
- 5
- 33
- 61
3
votes
3 answers
C++ - How to safely wrap malloc or emulate with the new operator
Is there a commonly accepted-as-safe approach to wrapping malloc in a function in C++? What I am attempting to do is allocat arbitrarily sized blocks of memory for holding the output of a function that writes binary values into a fixed size buffer…

Cloud
- 18,753
- 15
- 79
- 153
3
votes
3 answers
C++ Vector catch resize Memory Leak
I am trying to save a vector full of pointer to Circle objects.
Sometimes the bad_alloc catch works, but sometimes it doesn't, then I get the error message:
This application has requested the Runtime to terminate it in an unusual way.
Please…

Madeye
- 55
- 2
- 6
3
votes
5 answers
IPhone Objective C Memory Allocation
I understand that when using Alloc, new or copy you own the object and need to release the object. I understand that if I retain an object that I need to release it.
But if I have the following statment at the end of a method:
return [[UIImage…

NYTom
- 524
- 2
- 14
3
votes
2 answers
Memory allocation for an array of Objects - Is my understanding valid?
I have a question regarding memory allocation for Objects in an array. I am looking to create an array of Objects, but at compile time, I have no way of knowing how many objects I will need, and thus don't want to reserve more memory than…

Greg Steiner
- 647
- 1
- 9
- 20
2
votes
4 answers
Is there a way to shrink a memory allocation from the left in C without copying data?
I understand that the C standard library allows for the resizing of a memory allocation through the use of the realloc function, like in the following example:
char *a = malloc(10);
char *b = realloc(a, 8);
In this case, a and b could potentially…

Ddystopia
- 31
- 4
2
votes
3 answers
How to manage memory with images
Okay, so if I written quite a lot of code without ever allocating any objects, where is the memory going?
For example, rather than having
UIImage *myImage = [UIImage imageNamed:@"image.png"];
imageView.image = myImage;
[myImage release];
I…

user813031
- 61
- 5
2
votes
4 answers
Memory Allocation Question
I have a string which I am updating constantly (~33 times a second). It is used over and over and over again and is omnipresent in a loop I have going. This is the loop:
- (void)add{
int r = (arc4random() % 30) + 51;
long long debtInt =…

Peter Kazazes
- 3,600
- 7
- 31
- 60
2
votes
1 answer
App crashes when releasing a view properly
Hope you can help me with this problem.
I am having issues with the following code:
-(IBAction)swapViews:(id)sender{
myappAppDelegate *delegate = (myappAppDelegate *) [[UIApplication sharedApplication] delegate];
ThirdViewController…

Andres
- 101
- 1
- 9
2
votes
2 answers
Child class calls a method of the parent class
In objective-C I want to have a child class call or invoke a parent's method. As in the parent has allocated the child and the child does something that would invoke a parent method. like so:
//in the parent class
childObject *newChild =…

Danegraphics
- 447
- 1
- 7
- 21
2
votes
2 answers
Data going missing when passed between threads using a Singleton
Edit:
Thanks @BlackFrog. I think I'm nearer now, but the values are still not get getting through...
The values are set as shown by logs within [progressController updateProgressSummary:...] but are nil when I log them in progressUpdate…

Chris
- 1,449
- 1
- 18
- 39
2
votes
1 answer
Pointer and malloc in Swift
I am trying to convert this into swift.
Facing issue at memory allocation logic
Byte *p[10000];
p[allocatedMB] = malloc(1048576);
memset(p[allocatedMB], 0, 1048576);
How to write this in swift?

user1101733
- 258
- 2
- 14