Search Results

Search found 7 results on 1 pages for 'tofubeer'.

Page 1/1 | 1 

  • Objective-C memory model

    - by TofuBeer
    I am attempting to wrap my head around one part of the Objective-C memory model (specifically on the iPhone, so no GC). My background is C/C++/Java, and I am having an issue with the following bit of code (also wondering if I am doing this in an "Objective-C way" or not): - (NSSet *) retrieve { NSMutableSet *set; set = [NSMutableSet new]; // would normally fill the set in here with some data return ([set autorelease]); } - (void) test { NSSet *setA; NSSet *setB; setA = [self retrieve]; setB = [[self retrieve] retain]; [setA release]; [setB release]; } start EDIT Based on comments below, the updated retrieve method: - (NSSet *) retrieve { NSMutableSet *set; set = [[[NSMutableSet alloc] initWithCapacity:100] autorelease]; // would normally fill the set in here with some data return (set); } end EDIT The above code gives a warning for [setA release] "Incorrect decrement of the reference count of an object is not owned at this point by the caller". I though that the "new" set the reference count to 1. Then the "retain" call would add 1, and the "release" call would drop it by 1. Given that wouldn't setA have a reference count of 0 at the end and setB have a reference count of 1 at the end? From what I have figured out by trial and error, setB is correct, and there is no memory leak, but I'd like to understand why that is the case (what is wrong with my understanding of "new", "autorelease", "retain", and "release").

    Read the article

  • Dynamically formatting a string

    - by TofuBeer
    Before I wander off and roll my own I was wondering if anyone knows of a way to do the following sort of thing... Currently I am using MessageFormat to create some strings. I now have the requirement that some of those strings will have a variable number of arguments. For example (current code): MessageFormat.format("{0} OR {1}", array[0], array[1]); Now I need something like: // s will have "1 OR 2 OR 3" String s = format(new int[] { 1, 2, 3 }); and: // s will have "1 OR 2 OR 3 OR 4" String s = format(new int[] { 1, 2, 3, 4 }); There are a couple ways I can think of creating the format string, such as having 1 String per number of arguments (there is a finite number of them so this is practical, but seems bad), or build the string dynamically (there are a lot of them so this could be slow). Any other suggestions?

    Read the article

  • ExecutorService memory leak on exception

    - by TofuBeer
    I am having a hard time tracking this down since the profiler keeps crashing (hotspot error). Before I go too deep into figuring it out I'd like to know if I really have a problem or not :-) I have a few thread pools created via: Executors.newFixedThreadPool(10); The threads connect to different web sites and, on occasion, I get connection refused and wind up throwing an exception. When I later on call Future.get() to get the result it will then catch the ExecutionException that wraps the exception that was thrown when the connection could not be made. The program uses a fairly constant amount of memory up until the point in time that the exceptions get thrown (they tend to happen in batches when a particular site is overloaded). After that point the memory again remains constant but at a higher level. So my question is along the lines of is the memory behaviour (reported by "top" on Unix) expected because the exceptions just triggered something or do I probably have an actual leak that I'll need to track down? Additionally when Future.get() throws an exception is there anything else I need to do besides catch the exception (such as call Future.cancel() on it)?

    Read the article

  • ExecutorSerrvice memory leak on exception

    - by TofuBeer
    I am having a hard time tracking this down since the profiler keeps crashing (hotspot error). Before I go too deep into figuring it out I'd like to know if I really have a problem or not :-) I have a few thread pools created via: Executors.newFixedThreadPool(10); The threads connect to different web sites and, on occasion, I get connection refused and wind up throwing an exception. When I later on call Future.get() to get the result it will then catch the ExecutionException that wraps the exception that was thrown when the connection could not be made. The program uses a fairly constant amount of memory up until the point in time that the exceptions get thrown (they tend to happen in batches when a particular site is overloaded). After that point the memory again remains constant but at a higher level. So my question is along the lines of is the memory behaviour (reported by "top" on Unix) expected because the exceptions just triggered something or do I probably have an actual leak that I'll need to track down? Additionally when Future.get() throws an exception is there anything else I need to do besides catch the exception (such as call Future.cancel() on it)?

    Read the article

  • Does close ever throw an IOException?

    - by TofuBeer
    After providing some answers here, and reading some comments, it would seem that, in practice IOException is never thrown on close for file I/O. Are there any cases in which calling close on a Stream/Reader/Writer actually throws an IOException? If an exception is actually thrown, how should it be dealt with?

    Read the article

  • JPA atomic query/save for multithreaded app

    - by TofuBeer
    I am in the midst of changing my JPA code around to make use of threads. I have a separate entity manager and transaction for each thread. What I used to have (for the single threaded environment) was code like: // get object from the entity manager X x = getObjectX(jpaQuery); if(x == null) { x = new X(); x.setVariable(foo); entityManager.persist(x); } With that code in the multi threaded environment I am getting duplicate keys since, I assume, getObjectX returns null for a thread, then that thread is swapped out, the next thread calls getObjextX, also getting null, and then both threads will create and persist a new X(). Short of adding in synchronization, is there an atomic way to get/save-if-doesn't-exist a value with JPA or should I rethink my approach EDIT: I am using the latest Eclipselink and MySql 5.1

    Read the article

1