小编Ran*_* Ji的帖子

HashMap.clear() 减少内存?

System.gc();
System.out.println((Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024/1024);// print 1M

Map map=new HashMap();
for(int i=0;i<100000;i++){
    map.put("key"+i,"i");
}
System.gc();
System.out.println((Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024/1024); //print 10M

map.clear();
System.gc();
System.out.println((Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));//print less than 1M
Run Code Online (Sandbox Code Playgroud)

看来调用clear方法时内存会减少。然而,从其他答案来看,该clear方法似乎从未缩小HashMap. 那么为什么内存会减少呢?

java memory hashmap

2
推荐指数
2
解决办法
540
查看次数

导航控制器为零,当推送视图控制器时

有三个viewControllerMainViewController ViewControllerBViewControllerCMainViewController将在应用程序启动时加载。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];

    MainViewController * main = [[MainViewController alloc]init];
    UINavigationController * navigationController = [[UINavigationController alloc]initWithRootViewController:main];
    self.window.rootViewController = navigationController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    return YES;       
}
Run Code Online (Sandbox Code Playgroud)

并且有一个button关于MainViewController,现在ViewControllerB

UIViewController *rootViewController = [[UIApplication sharedApplication].keyWindow rootViewController];
ViewControllerB * vcb=[[ViewControllerB alloc] init];
[rootViewController presentViewController:vcb animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

在之后 …

xcode navigationcontroller ios

1
推荐指数
1
解决办法
6233
查看次数

标签 统计

hashmap ×1

ios ×1

java ×1

memory ×1

navigationcontroller ×1

xcode ×1