If I have a instance method and within this method I do something like this:
NSString *peopleString = [peopleList componentsJoinedByString: @", "];
...
UILabel *likeLabel = [[UILabel alloc] initWithFrame:CGRectMake(16.0+6.0f, 4.0f, 252.0f, 12.0f)];
[likeLabel setText:peopleString];
[likeLabel setFont:[UIFont fontWithName:@"Arial" size:1...
I was reading the C# entry on Wikipedia, and came across:
Managed memory cannot be explicitly freed; instead, it is automatically garbage collected.
Why is it that in languages with automatic memory management, manual management isn't even allowed? I can see that in most cases it wouldn't be necessary, but wouldn't it come in hand...
We have a 64bit C#/.Net3.0 application that runs on a 64bit Windows server. From time to time the app can use large amount of memory which is available. In some instances the application stops allocating additional memory and slows down significantly (500+ times slower).When I check the memory from the task manager the amount of the memo...
I understand that constant CStrings are allocated statically, rather than on the heap.
I also noticed that constant NSStrings have an infinite retain count. Does it hold true that constant NSStrings are also allocated statically, rather than on the heap?
...
Hello,
I have been solving a lot of memory leaks but have been unsuccessful in solving this one. There are tons of NSCF memory leaks coming due to [NSCFString substringWithRange:]. I have been checking all the String allocations and have released all of them at appropriate places. The responsible library: Foundation.
Has anyone encoun...
i.e. would cause the object to be released immediately and not have to be released by the pool if I did this?
[[NSArray arrayWithCapacity:100] release];
Can't find a clear explanation in the docs about this.
...
As mentioned in this answer simply calling the destructor for the second time is already undefined behavior 12.4/14(3.8).
For example:
class Class {
public:
~Class() {}
};
// somewhere in code:
{
Class* object = new Class();
object->~Class();
delete object; // UB because at this point the destructor call is attempted ag...
Given the two scenarios, which code is best practice and why?
Autorelease
loginButton = [[[UIBarButtonItem alloc] initWithTitle:@"Login"
style:UIBarButtonItemStylePlain
target:self
action:@s...
Hello, I am using a NSXMLParser class in my program and I assign a delegate to it.
This delegate, though, gets retained by the setDelegate: method resulting to a minor, yet annoying :-), memory leak.
I cannot release the delegate class after the setDelegate: because the program will crash.
Here is my code:
self.parserDelegate = [[Pars...
The following code doesn't compile for me in MSVC2005:
std::vector<CMenu> vec(10);
CMenu is an MFC menu object (such as a context menu). Through some testing I learned that CMenu does not have a public copy constructor.
To do what I wanted to do, I needed to use a dynamic array.
CMenu* menus = new CMenu[10];
// ...
delete [] menus;
...
I was going through one of the threads.
A program crashed because
It had declared an array of 10^6 locally inside a function.
Reason being given was memory allocation failure on stack leads to crash.
when same array was declared globally, it worked well.(memory on heap saved it).
Now for the moment ,Let us suppose,
stack grows downwar...
I need to refactor my project in order to make it immune to OutOfMemory exception.
There are huge collections used in my project and by changing one parameter I can make my program to be more accurate or use less of the memory...
OK, that's the background. What I would like to do is to run the routines in a loop:
Run the subroutine...
According to the rules of memory management in a non garbage collected world, one is not supposed to retain a the calling object in a delegate. Scenario goes like this:
I have a class that inherits from UITableViewController and contains a search bar. I run expensive search operations in a secondary thread. This is all done with an NSOp...
I have a part of code that operates on large arrays of double (containing about 6000 elements at least) and executes several hundred times (usually 800) .
When I use standard loop, like that:
double[] singleRow = new double[6000];
int maxI = 800;
for(int i=0; i<maxI; i++)
{
singleRow = someObject.producesOutput();
//...
// do somethin...
I know i can simulate a memory warning on the simulator by selecting 'Simulate Memory Warning' from the drop down menu of the iPhone Simulator. I can even make a hot key for that.
But this is not what I'd like to achieve. I'd like to do that from the code by simply, lets say doing it every 5 seconds. Is that possible?
...
I would like to handle out of memory errors in iPhone to execute logic with lesser memory requirements in case I run of of memory. In particular, I would like to do something very similar to the following pseudo-code:
UIImage* image;
try {
image = [UIImage imageNamed:@"high_quality_image.png"];
} catch (OutOfMemoryException e) {
...
Are there good video tuts that show how to use this Object Alloc instrument to figure out if my objects and other stuff get freed from memory? Also, I have a bunch of C code and use Core Audio, so those are not really objects but still heavy in memory. Would like to know more about that Object Alloc instrument.
...
I have an class method which generates a UIImage, like this:
+ (UIImage*)imageWithFileName:(NSString*)imgFile {
UIImage *img = nil;
NSBundle *appBundle = [NSBundle mainBundle];
NSString *resourcePath = [appBundle pathForResource:imgFile ofType:nil];
if (resourcePath != nil) {
NSURL *imageURL = [NSURL fileURLWit...
If I have a xib file with, say, a UIButton element, but I do not create an IBOutlet to it, will it be released automatically? Or do I need to create outlets to all UI elements, and release them, even if I don't necessarily need the outlet for other purposes?
...
I was trying to figure out how much memory I can malloc to maximum extent on my machine
(1 Gb RAM 160 Gb HD Windows platform).
I read that maximum memory malloc can allocate is limited to physical memory.(on heap)
Also when a program exceeds consumption of memory to a certain level, the computer stops working because other applications ...